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

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

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

Calendar.setTimeInMillis介绍

[英]Sets the time of this Calendar to the given Unix time. See Date for more about what this means.
[中]将此日历的时间设置为给定的Unix时间。有关这意味着什么的更多信息,请参见日期。

代码示例

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

@Override
  public Calendar convert(Long source) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(source);
    return calendar;
  }
}

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

public static long computNextHourTimeMillis() {
  Calendar cal = Calendar.getInstance();
  cal.setTimeInMillis(System.currentTimeMillis());
  cal.add(Calendar.DAY_OF_MONTH, 0);
  cal.add(Calendar.HOUR_OF_DAY, 1);
  cal.set(Calendar.MINUTE, 0);
  cal.set(Calendar.SECOND, 0);
  cal.set(Calendar.MILLISECOND, 0);
  return cal.getTimeInMillis();
}

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

public static Calendar convertToTimeZone(Calendar time, TimeZone timeZone) {
 Calendar foreignTime = new GregorianCalendar(timeZone);
 foreignTime.setTimeInMillis(time.getTimeInMillis());
 return foreignTime;
}

代码示例来源:origin: TeamNewPipe/NewPipe

@Override
  public String toString() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(timestamp);
    return "[" + calendar.getTime().toString() + "] " + location + File.separator + name;
  }
}

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

public Range getSearchRangeOnSingleValue(Object value) {
  if (Date.class.isAssignableFrom(dataType)) {
    Date center = (Date) value;
    Calendar cal = Calendar.getInstance();
    cal.setTime(center);
    cal.setTimeInMillis(cal.getTimeInMillis() - before.longValue());
    Date min = cal.getTime();
    cal.setTime(center);
    cal.setTimeInMillis(cal.getTimeInMillis() + after.longValue());
    Date max = cal.getTime();
    return new DateRange(min, max);
  }
  // TODO: add support for Number, e.g., elevation
  throw new IllegalArgumentException("Unsupported value type " + dataType);
}

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

public static String timeMillisToHumanString3(final long t) {
  Calendar cal = Calendar.getInstance();
  cal.setTimeInMillis(t);
  return String.format("%04d%02d%02d%02d%02d%02d",
    cal.get(Calendar.YEAR),
    cal.get(Calendar.MONTH) + 1,
    cal.get(Calendar.DAY_OF_MONTH),
    cal.get(Calendar.HOUR_OF_DAY),
    cal.get(Calendar.MINUTE),
    cal.get(Calendar.SECOND));
}

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

/**
 * Add or subtract interval value to the specified timestamp
 */
public Timestamp timestampChange(Timestamp in, boolean add) {
 Calendar c = Calendar.getInstance();
 c.setTimeInMillis(in.getTime());
 calendarChange(c, add);
 return new Timestamp(c.getTimeInMillis());
}

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

public RecordEventTimeDetail(long timeStamp) {
  Calendar calendar = Calendar.getInstance(timeZone, Locale.ROOT);
  calendar.setTimeInMillis(timeStamp);
  String yearStr = String.format(Locale.ROOT, "%04d", calendar.get(Calendar.YEAR));
  String monthStr = String.format(Locale.ROOT, "%02d", calendar.get(Calendar.MONTH) + 1);
  this.year_begin_date = yearStr + "-01-01";
  this.month_begin_date = yearStr + "-" + monthStr + "-01";
  this.date = dateFormat.format(calendar.getTime());
  this.time = timeFormat.format(calendar.getTime());
  this.hour = calendar.get(Calendar.HOUR_OF_DAY);
  this.minute = calendar.get(Calendar.MINUTE);
  this.second = calendar.get(Calendar.SECOND);
  timeStampForWeekBegin -= 3600000L * 24 * (calendar.get(Calendar.DAY_OF_WEEK) - 1);
  calendar.setTimeInMillis(timeStampForWeekBegin);
  this.week_begin_date = dateFormat.format(calendar.getTime());

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

@Override
public String toString() {
  Calendar expirationTime = Calendar.getInstance();
  expirationTime.setTimeInMillis(getExpiration());
  long remainingTime = expirationTime.getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
  SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS");
  dateFormat.setTimeZone(expirationTime.getTimeZone());
  String expirationTimeString = dateFormat.format(expirationTime.getTime());
  return new StringBuilder("LoginAuthenticationToken for ")
      .append(getName())
      .append(" issued by ")
      .append(getIssuer())
      .append(" expiring at ")
      .append(expirationTimeString)
      .append(" [")
      .append(getExpiration())
      .append(" ms, ")
      .append(remainingTime)
      .append(" ms remaining]")
      .toString();
}

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

public static Date getDate(final SharedPreferences prefs, final String key, final Date defValue) {
  if (!prefs.contains(key + "_value") || !prefs.contains(key + "_zone")) {
    return defValue;
  }
  Calendar calendar = Calendar.getInstance();
  calendar.setTimeInMillis(prefs.getLong(key + "_value", 0));
  calendar.setTimeZone(TimeZone.getTimeZone(prefs.getString(key + "_zone", TimeZone.getDefault().getID())));
  return calendar.getTime();
}

public static void putDate(final SharedPreferences prefs, final String key, final Date date, final TimeZone zone) {
  editor.edit().putLong(key + "_value", date.getTime()).apply();
  editor.edit().putString(key + "_zone", zone.getID()).apply();
}

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

/**
 * Perform month arithmetic to millis value using UTC time zone.
 * @param millis
 * @param months
 * @return
 */
public long addMonthsToMillis(long millis, int months) {
 calUtc.setTimeInMillis(millis);
 calUtc.add(Calendar.MONTH, months);
 return calUtc.getTimeInMillis();
}

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

public String convertTimeWithTimeZome(long time){
  Calendar cal = Calendar.getInstance();
  cal.setTimeZone(TimeZone.getTimeZone("UTC"));
  cal.setTimeInMillis(time);
  return (cal.get(Calendar.YEAR) + " " + (cal.get(Calendar.MONTH) + 1) + " " 
      + cal.get(Calendar.DAY_OF_MONTH) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":"
      + cal.get(Calendar.MINUTE));

}

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

public static Calendar asCalendar(Locale locale, TimeZone timeZone, boolean includeTime) {
    Calendar calendar = Calendar.getInstance(timeZone, locale);
    calendar.setTimeInMillis(asMillis());
    if (!includeTime) {
      calendar.set(Calendar.HOUR_OF_DAY, 0);
      calendar.set(Calendar.MINUTE, 0);
      calendar.set(Calendar.SECOND, 0);
      calendar.set(Calendar.MILLISECOND, 0);
    }
    return calendar;
  }
}

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

private void calToday(){
  mCalendar.setTimeInMillis(System.currentTimeMillis());
  mToday = mCalendar.get(Calendar.DAY_OF_MONTH);
  mTodayMonth = mCalendar.get(Calendar.MONTH);
  mTodayYear = mCalendar.get(Calendar.YEAR);
}

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

@Test
public void testDateType() {
  final long now = System.currentTimeMillis();
  final java.sql.Date original = new java.sql.Date( now );
  final java.sql.Date copy = new java.sql.Date( now );
  Calendar cal = new GregorianCalendar();
  cal.clear();
  cal.setTimeInMillis( now );
  cal.add( Calendar.YEAR, 1 );
  final java.sql.Date different = new java.sql.Date( cal.getTime().getTime() );
  runBasicTests( DateType.INSTANCE, original, copy, different );
}

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

Long gmtTime =1317951113613L; // 2.32pm NZDT
Long timezoneAlteredTime = 0L;

if (offset != 0L) {
  int multiplier = (offset*60)*(60*1000);
  timezoneAlteredTime = gmtTime + multiplier;
} else {
  timezoneAlteredTime = gmtTime;
}

Calendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(timezoneAlteredTime);

DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z");

formatter.setCalendar(calendar);
formatter.setTimeZone(TimeZone.getTimeZone(timeZone));

String newZealandTime = formatter.format(calendar.getTime());

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

public static long computNextMinutesTimeMillis() {
  Calendar cal = Calendar.getInstance();
  cal.setTimeInMillis(System.currentTimeMillis());
  cal.add(Calendar.DAY_OF_MONTH, 0);
  cal.add(Calendar.HOUR_OF_DAY, 0);
  cal.add(Calendar.MINUTE, 1);
  cal.set(Calendar.SECOND, 0);
  cal.set(Calendar.MILLISECOND, 0);
  return cal.getTimeInMillis();
}

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

long timeInMillis = System.currentTimeMillis();
Calendar cal1 = Calendar.getInstance();
cal1.setTimeInMillis(timeInMillis);
SimpleDateFormat dateFormat = new SimpleDateFormat(
                "dd/MM/yyyy hh:mm:ss a");
dateforrow = dateFormat.format(cal1.getTime());

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

Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTime(date);
LocalDateTime check = LocalDateTime.fromCalendarFields(calendar);
    calendar.setTimeInMillis(calendar.getTimeInMillis() + 60000);
    check = LocalDateTime.fromCalendarFields(calendar);
    calendar.setTimeInMillis(calendar.getTimeInMillis() - 1000);
    check = LocalDateTime.fromCalendarFields(calendar);
  calendar.setTimeInMillis(calendar.getTimeInMillis() + 1000);
} else if (check.equals(this)) {
  final Calendar earlier = Calendar.getInstance(timeZone);
  earlier.setTimeInMillis(calendar.getTimeInMillis() - timeZone.getDSTSavings());
  check = LocalDateTime.fromCalendarFields(earlier);
  if (check.equals(this)) {
return calendar.getTime();

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

public static String timeMillisToHumanString(final long t) {
  Calendar cal = Calendar.getInstance();
  cal.setTimeInMillis(t);
  return String.format("%04d%02d%02d%02d%02d%02d%03d", cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1,
    cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND),
    cal.get(Calendar.MILLISECOND));
}

相关文章