java.util.Calendar.get()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(145)

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

Calendar.get介绍

[英]Returns the value of the given field after computing the field values by calling complete() first.
[中]

代码示例

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

import java.util.Calendar

Calendar c = Calendar.getInstance(); 
int seconds = c.get(Calendar.SECOND);

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

Date date; // your date
 Calendar cal = Calendar.getInstance();
 cal.setTime(date);
 int year = cal.get(Calendar.YEAR);
 int month = cal.get(Calendar.MONTH);
 int day = cal.get(Calendar.DAY_OF_MONTH);
 // etc.

代码示例来源:origin: stanfordnlp/CoreNLP

private static Calendar copyCalendar(Calendar c) {
  Calendar date = Calendar.getInstance();
  date.clear();
  date.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.HOUR_OF_DAY), c
    .get(Calendar.MINUTE), c.get(Calendar.SECOND));
  return date;
 }
}

代码示例来源:origin: jmdhappy/xxpay-master

public static Date getFirstDate(){
  Calendar calendar = Calendar.getInstance();
  int month = calendar.get(Calendar.MONTH);
  int year = calendar.get(Calendar.YEAR);
  calendar.set(year, month, 1);
  return calendar.getTime();
}

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

Calendar c = Calendar.getInstance();
 int mYear = c.get(Calendar.YEAR);
 int mMonth = c.get(Calendar.MONTH);
 int mDay = c.get(Calendar.DAY_OF_MONTH);
 System.out.println("the selected " + mDay);
 DatePickerDialog dialog = new DatePickerDialog(Registration.this,
     new mDateSetListener(), mYear, mMonth, mDay);
 dialog.show();

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

Calendar rightNow = Calendar.getInstance();

// offset to add since we're not UTC
long offset = rightNow.get(Calendar.ZONE_OFFSET) +
  rightNow.get(Calendar.DST_OFFSET);
long sinceMidnight = (rightNow.getTimeInMillis() + offset) %
  (24 * 60 * 60 * 1000);

System.out.println(sinceMidnight + " milliseconds since midnight");

代码示例来源:origin: org.apache.ant/ant

/**
 * Report locale information
 * @param out stream to print to
 */
private static void doReportLocale(PrintStream out) {
  //calendar stuff.
  Calendar cal = Calendar.getInstance();
  TimeZone tz = cal.getTimeZone();
  out.println("Timezone "
      + tz.getDisplayName()
      + " offset="
      + tz.getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), cal
          .get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal
          .get(Calendar.DAY_OF_WEEK), ((cal.get(Calendar.HOUR_OF_DAY)
          * MINUTES_PER_HOUR + cal.get(Calendar.MINUTE))
          * SECONDS_PER_MINUTE + cal.get(Calendar.SECOND))
          * SECONDS_PER_MILLISECOND + cal.get(Calendar.MILLISECOND)));
}

代码示例来源:origin: pentaho/pentaho-kettle

public static Object getFiscalDate( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
 Object FunctionContext ) {
 if ( ArgList.length == 2 ) {
  try {
   if ( isNull( ArgList ) ) {
    return null;
   } else if ( isUndefined( ArgList ) ) {
    return undefinedValue;
   }
   java.util.Date dIn = (java.util.Date) ArgList[0];
   Calendar startDate = Calendar.getInstance();
   Calendar fisStartDate = Calendar.getInstance();
   Calendar fisOffsetDate = Calendar.getInstance();
   startDate.setTime( dIn );
   Format dfFormatter = new SimpleDateFormat( "dd.MM.yyyy" );
   String strOffsetDate = (String) ArgList[1] + String.valueOf( startDate.get( Calendar.YEAR ) );
   java.util.Date dOffset = (java.util.Date) dfFormatter.parseObject( strOffsetDate );
   fisOffsetDate.setTime( dOffset );
   String strFisStartDate = "01.01." + String.valueOf( startDate.get( Calendar.YEAR ) + 1 );
   fisStartDate.setTime( (java.util.Date) dfFormatter.parseObject( strFisStartDate ) );
   int iDaysToAdd = (int) ( ( startDate.getTimeInMillis() - fisOffsetDate.getTimeInMillis() ) / 86400000 );
   fisStartDate.add( Calendar.DATE, iDaysToAdd );
   return fisStartDate.getTime();
  } catch ( Exception e ) {
   throw new RuntimeException( e.toString() );
  }
 } else {
  throw new RuntimeException( "The function call getFiscalDate requires 2 arguments." );
 }
}

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

public static long getQuarterStart(long ts) {
  Calendar calendar = Calendar.getInstance(gmt, Locale.ROOT);
  calendar.setTimeInMillis(ts);
  int year = calendar.get(Calendar.YEAR);
  int month = calendar.get(Calendar.MONTH);
  calendar.clear();
  calendar.set(year, month / 3 * 3, 1);
  return calendar.getTimeInMillis();
}

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

Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.setTimeInMillis(timestamp);
while (calendar.get(Calendar.DAY_OF_WEEK) > calendar.getFirstDayOfWeek()) {
  calendar.add(Calendar.DATE, -1); // Substract 1 day until first day of week.
}
long firstDayOfWeekTimestamp = calendar.getTimeInMillis();

代码示例来源:origin: spring-projects/spring-framework

calendar.setTime(date);
calendar.set(Calendar.MILLISECOND, 0);
long originalTimestamp = calendar.getTimeInMillis();
doNext(calendar, calendar.get(Calendar.YEAR));
  calendar.add(Calendar.SECOND, 1);
  doNext(calendar, calendar.get(Calendar.YEAR));
return calendar.getTime();

代码示例来源:origin: alibaba/fastjson

DateFormat format = serializer.getDateFormat();
if (format == null) {
  format = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, serializer.locale);
  format.setTimeZone(serializer.timeZone);
out.write(quote);
Calendar calendar = Calendar.getInstance(serializer.timeZone, serializer.locale);
calendar.setTimeInMillis(time);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
int millis = calendar.get(Calendar.MILLISECOND);

代码示例来源:origin: springside/springside4

private static int getWithMondayFirst(final Date date, int field) {
  Validate.notNull(date, "The date must not be null");
  Calendar cal = Calendar.getInstance();
  cal.setFirstDayOfWeek(Calendar.MONDAY);
  cal.setTime(date);
  return cal.get(field);
}

代码示例来源:origin: jmdhappy/xxpay-master

public static Map<String,String> getPreMonth(){
  Map<String,String> rst = new HashMap<String,String>();
  Calendar calendar = Calendar.getInstance();
  calendar.add(Calendar.MONTH, -1);
  int year = calendar.get(Calendar.YEAR);
  int month = calendar.get(Calendar.MONTH);
  month = month + 1;
  rst.put("year", year+"");
  if(month > 12){
    rst.put("month", "12");
  }else{
    rst.put("month", month+"");
  }
  return rst;
}

代码示例来源:origin: quartz-scheduler/quartz

private boolean daylightSavingHourShiftOccurredAndAdvanceNeeded(Calendar newTime, int initialHourOfDay, Date afterTime) {
  if(isPreserveHourOfDayAcrossDaylightSavings() && newTime.get(Calendar.HOUR_OF_DAY) != initialHourOfDay) {
    newTime.set(Calendar.HOUR_OF_DAY, initialHourOfDay);
    if (newTime.get(Calendar.HOUR_OF_DAY) != initialHourOfDay) {
      return isSkipDayIfHourDoesNotExist();
    } else {
      return !newTime.getTime().after(afterTime);
    }
  }
  return false;
}

代码示例来源:origin: robovm/robovm

private SimpleDateFormat(Locale locale) {
  numberFormat = NumberFormat.getInstance(locale);
  numberFormat.setParseIntegerOnly(true);
  numberFormat.setGroupingUsed(false);
  calendar = new GregorianCalendar(locale);
  calendar.add(Calendar.YEAR, -80);
  creationYear = calendar.get(Calendar.YEAR);
  defaultCenturyStart = calendar.getTime();
}

代码示例来源:origin: redisson/redisson

/**
 * Advance the calendar to the particular hour paying particular attention
 * to daylight saving problems.
 * 
 * @param cal the calendar to operate on
 * @param hour the hour to set
 */
protected void setCalendarHour(Calendar cal, int hour) {
  cal.set(java.util.Calendar.HOUR_OF_DAY, hour);
  if (cal.get(java.util.Calendar.HOUR_OF_DAY) != hour && hour != 24) {
    cal.set(java.util.Calendar.HOUR_OF_DAY, hour + 1);
  }
}

代码示例来源:origin: rey5137/material

private static long gotoFirstDayOfWeek(Calendar cal){
  int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
  int firstDayOfWeek = cal.getFirstDayOfWeek();
  int shift = dayOfWeek >= firstDayOfWeek ? (dayOfWeek - firstDayOfWeek) : (dayOfWeek + 7 - firstDayOfWeek);
  cal.add(Calendar.DAY_OF_MONTH, -shift);
  return cal.getTimeInMillis();
}

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

protected Calendar nextDay(Date date, int dayOfWeek) {
 calendar.setTime(date);
 int currDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
 int daysToAdd;
 if (currDayOfWeek < dayOfWeek) {
  daysToAdd = dayOfWeek - currDayOfWeek;
 } else {
  daysToAdd = 7 - currDayOfWeek + dayOfWeek;
 }
 calendar.add(Calendar.DATE, daysToAdd);
 return calendar;
}

代码示例来源:origin: jenkinsci/jenkins

@Override
  void setTo(Calendar c, int i) {
    int v = i-offset;
    int was = c.get(field);
    c.set(field,v);
    final int firstDayOfWeek = c.getFirstDayOfWeek();
    if (v < firstDayOfWeek && was >= firstDayOfWeek) {
      // in crontab, the first DoW is always Sunday, but in Java, it can be Monday or in theory arbitrary other days.
      // When first DoW is 1/2 Monday, calendar points to 1/2 Monday, setting the DoW to Sunday makes
      // the calendar moves forward to 1/8 Sunday, instead of 1/1 Sunday. So we need to compensate that effect here.
      addTo(c,-7);
    } else if (was < firstDayOfWeek && firstDayOfWeek <= v) {
      // If we wrap the other way around, we need to adjust in the opposite direction of above.
      addTo(c, 7);
    }
  }
};

相关文章