java.util.Date.getYear()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中java.util.Date.getYear()方法的一些代码示例,展示了Date.getYear()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.getYear()方法的具体详情如下:
包路径:java.util.Date
类名称:Date
方法名:getYear

Date.getYear介绍

[英]Returns the gregorian calendar year since 1900 for this Date object.
[中]返回此日期对象自1900年以来的公历年。

代码示例

代码示例来源:origin: ZHENFENG13/My-Blog

public static boolean isToday(Date date) {
  Date now = new Date();
  boolean result = true;
  result &= date.getYear() == now.getYear();
  result &= date.getMonth() == now.getMonth();
  result &= date.getDate() == now.getDate();
  return result;
}

代码示例来源:origin: stackoverflow.com

Date now = new Date();     // Gets the current date and time
int year = now.getYear();  // Returns the # of years since 1900

代码示例来源:origin: prestodb/presto

/**
 * Constructs a YearMonth from a <code>java.util.Date</code>
 * using exactly the same field values avoiding any time zone effects.
 * <p>
 * Each field is queried from the Date and assigned to the YearMonth.
 * <p>
 * This factory method always creates a YearMonth with ISO chronology.
 *
 * @param date  the Date to extract fields from
 * @return the created YearMonth, never null
 * @throws IllegalArgumentException if the calendar is null
 * @throws IllegalArgumentException if the year or month is invalid for the ISO chronology
 */
@SuppressWarnings("deprecation")
public static YearMonth fromDateFields(Date date) {
  if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
  }
  return new YearMonth(date.getYear() + 1900, date.getMonth() + 1);
}

代码示例来源:origin: stackoverflow.com

Date today = new Date();                   
Date myDate = new Date(today.getYear(),today.getMonth()-1,today.getDay());
System.out.println("My Date is"+myDate);    
System.out.println("Today Date is"+today);
if (today.compareTo(myDate)<0)
  System.out.println("Today Date is Lesser than my Date");
else if (today.compareTo(myDate)>0)
  System.out.println("Today Date is Greater than my date"); 
else
  System.out.println("Both Dates are equal");

代码示例来源:origin: prestodb/presto

/**
 * Constructs a YearMonthDay from a <code>java.util.Date</code>
 * using exactly the same field values avoiding any time zone effects.
 * <p>
 * Each field is queried from the Date and assigned to the YearMonthDay.
 * This is useful if you have been using the Date as a local date,
 * ignoring the zone.
 * <p>
 * This factory method always creates a YearMonthDay with ISO chronology.
 *
 * @param date  the Date to extract fields from
 * @return the created YearMonthDay
 * @throws IllegalArgumentException if the calendar is null
 * @throws IllegalArgumentException if the date is invalid for the ISO chronology
 * @since 1.2
 */
public static YearMonthDay fromDateFields(Date date) {
  if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
  }
  return new YearMonthDay(
    date.getYear() + 1900,
    date.getMonth() + 1,
    date.getDate()
  );
}

代码示例来源:origin: apache/hbase

/**
 * Checks if the mob file is expired.
 * @param column The descriptor of the current column family.
 * @param current The current time.
 * @param fileDate The date string parsed from the mob file name.
 * @return True if the mob file is expired.
 */
public static boolean isMobFileExpired(ColumnFamilyDescriptor column, long current, String fileDate) {
 if (column.getMinVersions() > 0) {
  return false;
 }
 long timeToLive = column.getTimeToLive();
 if (Integer.MAX_VALUE == timeToLive) {
  return false;
 }
 Date expireDate = new Date(current - timeToLive * 1000);
 expireDate = new Date(expireDate.getYear(), expireDate.getMonth(), expireDate.getDate());
 try {
  Date date = parseDate(fileDate);
  if (date.getTime() < expireDate.getTime()) {
   return true;
  }
 } catch (ParseException e) {
  LOG.warn("Failed to parse the date " + fileDate, e);
  return false;
 }
 return false;
}

代码示例来源:origin: com.google.gwt/gwt-servlet

private void setDate(Date date) {
 if (getDatePicker().isYearAndMonthDropdownVisible()) {
  // setup months dropdown
  int month = date.getMonth();
  monthSelect.setSelectedIndex(month);
  // setup years dropdown
  yearSelect.clear();
  int year = date.getYear();
  int startYear = year - getNoOfYearsToDisplayBefore();
  int endYear = year + getNoOfYearsToDisplayAfter();
  Date newDate = new Date();
  for (int i = startYear; i <= endYear; i++) {
   newDate.setYear(i);
   yearSelect.addItem(getModel().getYearFormatter().format(newDate));
  }
  yearSelect.setSelectedIndex(year - startYear);
 } else {
  grid.setText(0, monthColumn, getModel().formatCurrentMonthAndYear());
 }
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testComponent() {
  Session s = openSession();
  Transaction t = s.beginTransaction();
  User u = new User( "gavin", "secret", new Person("Gavin King", new Date(), "Karbarook Ave") );
  s.persist(u);
  s.flush();
  u.getPerson().changeAddress("Phipps Place");
  t.commit();
  s.close();
  
  s = openSession();
  t = s.beginTransaction();
  u = (User) s.get(User.class, "gavin");
  assertEquals( u.getPerson().getAddress(), "Phipps Place" );
  assertEquals( u.getPerson().getPreviousAddress(), "Karbarook Ave" );
  assertEquals( u.getPerson().getYob(), u.getPerson().getDob().getYear()+1900 );
  u.setPassword("$ecret");
  t.commit();
  s.close();
  s = openSession();
  t = s.beginTransaction();
  u = (User) s.get(User.class, "gavin");
  assertEquals( u.getPerson().getAddress(), "Phipps Place" );
  assertEquals( u.getPerson().getPreviousAddress(), "Karbarook Ave" );
  assertEquals( u.getPassword(), "$ecret" );
  s.delete(u);
  t.commit();
  s.close();
}

代码示例来源:origin: joda-time/joda-time

/**
 * Constructs a YearMonthDay from a <code>java.util.Date</code>
 * using exactly the same field values avoiding any time zone effects.
 * <p>
 * Each field is queried from the Date and assigned to the YearMonthDay.
 * This is useful if you have been using the Date as a local date,
 * ignoring the zone.
 * <p>
 * This factory method always creates a YearMonthDay with ISO chronology.
 *
 * @param date  the Date to extract fields from
 * @return the created YearMonthDay
 * @throws IllegalArgumentException if the calendar is null
 * @throws IllegalArgumentException if the date is invalid for the ISO chronology
 * @since 1.2
 */
public static YearMonthDay fromDateFields(Date date) {
  if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
  }
  return new YearMonthDay(
    date.getYear() + 1900,
    date.getMonth() + 1,
    date.getDate()
  );
}

代码示例来源:origin: joda-time/joda-time

/**
 * Constructs a YearMonth from a <code>java.util.Date</code>
 * using exactly the same field values avoiding any time zone effects.
 * <p>
 * Each field is queried from the Date and assigned to the YearMonth.
 * <p>
 * This factory method always creates a YearMonth with ISO chronology.
 *
 * @param date  the Date to extract fields from
 * @return the created YearMonth, never null
 * @throws IllegalArgumentException if the calendar is null
 * @throws IllegalArgumentException if the year or month is invalid for the ISO chronology
 */
@SuppressWarnings("deprecation")
public static YearMonth fromDateFields(Date date) {
  if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
  }
  return new YearMonth(date.getYear() + 1900, date.getMonth() + 1);
}

代码示例来源:origin: h2oai/h2o-3

/**
 * Instantiate an AutoML object and start it running.  Progress can be tracked via its job().
 *
 * @param buildSpec
 * @return
 */
public static AutoML startAutoML(AutoMLBuildSpec buildSpec) {
 Date startTime = new Date();  // this is the one and only startTime for this run
 synchronized (AutoML.class) {
  // protect against two runs whose startTime is the same second
  if (lastStartTime != null) {
   while (lastStartTime.getYear() == startTime.getYear() &&
       lastStartTime.getMonth() == startTime.getMonth() &&
       lastStartTime.getDate() == startTime.getDate() &&
       lastStartTime.getHours() == startTime.getHours() &&
       lastStartTime.getMinutes() == startTime.getMinutes() &&
       lastStartTime.getSeconds() == startTime.getSeconds())
    startTime = new Date();
  }
  lastStartTime = startTime;
 }
 String keyString = buildSpec.build_control.project_name;
 AutoML aml = AutoML.makeAutoML(Key.<AutoML>make(keyString), startTime, buildSpec);
 DKV.put(aml);
 startAutoML(aml);
 return aml;
}

代码示例来源:origin: openmrs/openmrs-core

@Test
public void retirePatientIdentifierType_shouldRetireAndSetReasonAndRetiredByAndDate() {
  PatientService ps = Context.getPatientService();
  PatientIdentifierType pit = ps.getPatientIdentifierType(1);
  String reason = "moved away";
  PatientIdentifierType result = ps.retirePatientIdentifierType(pit, reason);
  assertTrue(result.getRetired());
  assertEquals(result.getRetireReason(), reason);
  assertEquals(result.getRetiredBy(), Context.getAuthenticatedUser());
  Date today = new Date();
  Date dateRetired = result.getDateRetired();
  assertEquals(dateRetired.getDay(), today.getDay());
  assertEquals(dateRetired.getMonth(), today.getMonth());
  assertEquals(dateRetired.getYear(), today.getYear());
}

代码示例来源:origin: com.google.gwt/gwt-servlet

Date date = new Date();
@SuppressWarnings("deprecation")
int defaultCenturyStartYear = date.getYear() + 1900 - 80;
int ambiguousTwoDigitYear = defaultCenturyStartYear % 100;
cal.setAmbiguousYear(value == ambiguousTwoDigitYear);

代码示例来源:origin: JodaOrg/joda-time

/**
 * Constructs a YearMonthDay from a <code>java.util.Date</code>
 * using exactly the same field values avoiding any time zone effects.
 * <p>
 * Each field is queried from the Date and assigned to the YearMonthDay.
 * This is useful if you have been using the Date as a local date,
 * ignoring the zone.
 * <p>
 * This factory method always creates a YearMonthDay with ISO chronology.
 *
 * @param date  the Date to extract fields from
 * @return the created YearMonthDay
 * @throws IllegalArgumentException if the calendar is null
 * @throws IllegalArgumentException if the date is invalid for the ISO chronology
 * @since 1.2
 */
public static YearMonthDay fromDateFields(Date date) {
  if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
  }
  return new YearMonthDay(
    date.getYear() + 1900,
    date.getMonth() + 1,
    date.getDate()
  );
}

代码示例来源:origin: JodaOrg/joda-time

/**
 * Constructs a YearMonth from a <code>java.util.Date</code>
 * using exactly the same field values avoiding any time zone effects.
 * <p>
 * Each field is queried from the Date and assigned to the YearMonth.
 * <p>
 * This factory method always creates a YearMonth with ISO chronology.
 *
 * @param date  the Date to extract fields from
 * @return the created YearMonth, never null
 * @throws IllegalArgumentException if the calendar is null
 * @throws IllegalArgumentException if the year or month is invalid for the ISO chronology
 */
@SuppressWarnings("deprecation")
public static YearMonth fromDateFields(Date date) {
  if (date == null) {
    throw new IllegalArgumentException("The date must not be null");
  }
  return new YearMonth(date.getYear() + 1900, date.getMonth() + 1);
}

代码示例来源:origin: stackoverflow.com

Date MiladiDate = new Date();
calcSolarCalendar(MiladiDate);
int miladiYear = MiladiDate.getYear() + 1900;
int miladiMonth = MiladiDate.getMonth() + 1;
int miladiDate = MiladiDate.getDate();
int WeekDay = MiladiDate.getDay();

代码示例来源:origin: net.sf.advanced-gwt/advanced-gwt

/**
 * This method returns the first date of the month.
 *
 * @return the first date of the month.
 */
public Date getFirstDayOfMonth() {
  return new Date(date.getYear(), date.getMonth(), 1);
}

代码示例来源:origin: apache/phoenix

@Test
public void testCurrentTimeWithProjectedTable () throws Exception {
  String tableName1 = generateUniqueName();
  String tableName2 = generateUniqueName();
  String ddl = "CREATE TABLE " + tableName1 + " ( ID integer primary key)";
  conn.createStatement().execute(ddl);
  ddl = "CREATE TABLE " + tableName2 + " ( ID integer primary key)";
  conn.createStatement().execute(ddl);
  String ups = "UPSERT INTO " + tableName1 + " VALUES (1)";
  conn.createStatement().execute(ups);
  ups = "UPSERT INTO " + tableName2 + " VALUES (1)";
  conn.createStatement().execute(ups);
  conn.commit();
  ResultSet rs = conn.createStatement().executeQuery("select /*+ USE_SORT_MERGE_JOIN */ op" +
      ".id, current_time() from " +tableName1 + " op where op.id in (select id from " + tableName2 + ")");
  assertTrue(rs.next());
  assertEquals(new java.util.Date().getYear(),rs.getTimestamp(2).getYear());
}

代码示例来源:origin: joda-time/joda-time

date.getYear() + 1900,
  date.getMonth() + 1,
  date.getDate()
);

代码示例来源:origin: TommyLemon/APIJSON

/**根据生日获取年龄
 * @param birthday
 * @return
 */
public static int getAge(Date birthday) {
  if (birthday == null) {
    return 0;
  }
  if (birthday.getYear() > getDateDetail(System.currentTimeMillis())[0]) {
    birthday.setYear(birthday.getYear() - TimeUtil.SYSTEM_START_DATE[0]);
  }
  return getAge(new int[]{birthday.getYear(), birthday.getMonth(), birthday.getDay()});
}
/**根据生日获取年龄

相关文章