本文整理了Java中java.util.Date.setTime()
方法的一些代码示例,展示了Date.setTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.setTime()
方法的具体详情如下:
包路径:java.util.Date
类名称:Date
方法名:setTime
[英]Sets this Date to the specified millisecond value. The value is the number of milliseconds since Jan. 1, 1970 GMT.
[中]将此日期设置为指定的毫秒值。该值是自1970年1月1日GMT以来的毫秒数。
代码示例来源:origin: apache/flink
@Override
public Date copy(Date from, Date reuse) {
if (from == null) {
return null;
}
reuse.setTime(from.getTime());
return reuse;
}
代码示例来源:origin: stackoverflow.com
Date date = new Date ();
date.setTime((long)unix_time*1000);
代码示例来源:origin: ZHENFENG13/My-Blog
public static String getDaysAgo(int interval) {
Date date = new Date();
long time = date.getTime() / 1000L - (long)(interval * 60 * 60 * 24);
date.setTime(time * 1000L);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
return format.format(date);
} catch (Exception var6) {
System.out.println(var6.getMessage());
return "";
}
}
代码示例来源:origin: quartz-scheduler/quartz
/**
* Translate a date & time from a users time zone to the another
* (probably server) time zone to assist in creating a simple trigger with
* the right date & time.
*
* @param date the date to translate
* @param src the original time-zone
* @param dest the destination time-zone
* @return the translated date
*/
public static Date translateTime(Date date, TimeZone src, TimeZone dest) {
Date newDate = new Date();
int offset = (dest.getOffset(date.getTime()) - src.getOffset(date.getTime()));
newDate.setTime(date.getTime() - offset);
return newDate;
}
代码示例来源:origin: rapidoid/rapidoid
public static byte[] getDateTimeBytes() {
long time = System.currentTimeMillis();
// avoid synchronization for better performance
if (time >= updateCurrDateAfter) {
// RFC 1123 date-time format, e.g. Sun, 07 Sep 2014 00:17:29 GMT
DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.ROOT);
dateFormat.setTimeZone(GMT);
Date date = new Date();
date.setTime(time);
CURR_DATE_BYTES = dateFormat.format(date).getBytes();
updateCurrDateAfter = time - (time % 1000) + 1000;
}
return CURR_DATE_BYTES;
}
代码示例来源:origin: ZHENFENG13/My-Blog
public static Date getNextDay(Date date) {
long time = date.getTime() / 1000L + 86400L;
date.setTime(time * 1000L);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
date = format.parse(format.format(date));
} catch (Exception var5) {
System.out.println(var5.getMessage());
}
return date;
}
代码示例来源:origin: com.google.gwt/gwt-servlet
Date tmp = new Date(date.getYear(), date.getMonth(), 35);
int daysInCurrentMonth = 35 - tmp.getDate();
date.setDate(Math.min(daysInCurrentMonth, orgDayOfMonth));
date.setTime(date.getTime() / 1000 * 1000 + this.milliseconds);
Date defaultCenturyStart = new Date();
defaultCenturyStart.setYear(defaultCenturyStart.getYear() - 80);
if (date.before(defaultCenturyStart)) {
date.setTime(date.getTime() + (this.tzOffset - offset) * 60 * 1000);
代码示例来源:origin: ZHENFENG13/My-Blog
public static Date getTomorrow() {
Date date = new Date();
long time = date.getTime() / 1000L + 86400L;
date.setTime(time * 1000L);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
date = format.parse(format.format(date));
} catch (Exception var5) {
System.out.println(var5.getMessage());
}
return date;
}
代码示例来源:origin: quartz-scheduler/quartz
/**
* Translate a date & time from a users time zone to the another
* (probably server) time zone to assist in creating a simple trigger with
* the right date & time.
*
* @param date the date to translate
* @param src the original time-zone
* @param dest the destination time-zone
* @return the translated date
*/
public static Date translateTime(Date date, TimeZone src, TimeZone dest) {
Date newDate = new Date();
int offset = (dest.getOffset(date.getTime()) - src.getOffset(date.getTime()));
newDate.setTime(date.getTime() - offset);
return newDate;
}
代码示例来源:origin: log4j/log4j
public void activateOptions() {
super.activateOptions();
if(datePattern != null && fileName != null) {
now.setTime(System.currentTimeMillis());
sdf = new SimpleDateFormat(datePattern);
int type = computeCheckPeriod();
printPeriodicity(type);
rc.setType(type);
File file = new File(fileName);
scheduledFilename = fileName+sdf.format(new Date(file.lastModified()));
} else {
LogLog.error("Either File or DatePattern options are not set for appender ["
+name+"].");
}
}
代码示例来源:origin: ZHENFENG13/My-Blog
public static Date getYesterday(Date date) {
long time = date.getTime() / 1000L - 86400L;
date.setTime(time * 1000L);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
date = format.parse(format.format(date));
} catch (Exception var5) {
System.out.println(var5.getMessage());
}
return date;
}
代码示例来源:origin: stackoverflow.com
i.putExtra("date", date.getTime());
Date d = new Date();
d.setTime(i.getLongExtra("date", -1));
代码示例来源:origin: auth0/java-jwt
private void assertDateIsFuture(Date date, long leeway, Date today) {
today.setTime(today.getTime() - leeway * 1000);
if (date != null && today.after(date)) {
throw new TokenExpiredException(String.format("The Token has expired on %s.", date));
}
}
代码示例来源:origin: ZHENFENG13/My-Blog
public static Date getWeekAgo() {
Date date = new Date();
long time = date.getTime() / 1000L - 604800L;
date.setTime(time * 1000L);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
date = format.parse(format.format(date));
} catch (Exception var5) {
System.out.println(var5.getMessage());
}
return date;
}
代码示例来源:origin: ZHENFENG13/My-Blog
public static Date dateAdd(int interval, Date date, int n) {
long time = date.getTime() / 1000L;
switch(interval) {
case 1:
time += (long)(n * 86400);
break;
case 2:
time += (long)(n * 604800);
break;
case 3:
time += (long)(n * 2678400);
break;
case 4:
time += (long)(n * 31536000);
break;
case 5:
time += (long)(n * 3600);
break;
case 6:
time += (long)(n * 60);
break;
case 7:
time += (long)n;
}
Date result = new Date();
result.setTime(time * 1000L);
return result;
}
代码示例来源:origin: apache/rocketmq
public void activateOptions() {
super.activateOptions();
if (datePattern != null && fileName != null) {
now.setTime(System.currentTimeMillis());
sdf = new SimpleDateFormat(datePattern);
int type = computeCheckPeriod();
printPeriodicity(type);
rc.setType(type);
File file = new File(fileName);
scheduledFilename = fileName + sdf.format(new Date(file.lastModified()));
} else {
SysLogger.error("Either File or DatePattern options are not set for appender [" + name + "].");
}
}
代码示例来源:origin: ZHENFENG13/My-Blog
public static Date yesterday(Date date) {
Date newDate = (Date)date.clone();
long time = newDate.getTime() / 1000L - 86400L;
newDate.setTime(time * 1000L);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
newDate = format.parse(format.format(newDate));
} catch (Exception var6) {
System.out.println(var6.getMessage());
}
return newDate;
}
代码示例来源:origin: stackoverflow.com
Immutable imm = new Immutable("John", new Date());
imm.getName(); //safe
Date dateOfBirth = imm.getDateOfBirth();
//hundreds of lines later
dateOfBirth.setTime(0); //we just modified `imm` object
代码示例来源:origin: auth0/java-jwt
private void assertDateIsPast(Date date, long leeway, Date today) {
today.setTime(today.getTime() + leeway * 1000);
if (date != null && today.before(date)) {
throw new InvalidClaimException(String.format("The Token can't be used before %s.", date));
}
}
代码示例来源:origin: ZHENFENG13/My-Blog
public static Date getYesterday() {
Date date = new Date();
long time = date.getTime() / 1000L - 86400L;
date.setTime(time * 1000L);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
date = format.parse(format.format(date));
} catch (Exception var5) {
System.out.println(var5.getMessage());
}
return date;
}
内容来源于网络,如有侵权,请联系作者删除!