本文整理汇总了Java中java.util.Date.getTime方法的典型用法代码示例。如果您正苦于以下问题:Java Date.getTime方法的具体用法?Java Date.getTime怎么用?Java Date.getTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Date
的用法示例。
在下文中一共展示了Date.getTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nextDay
import java.util.Date; //导入方法依赖的package包/类
/**
* @param date
* @return 复制新Date,不改变参数
*/
public static Date nextDay(Date date) {
Date newDate = (Date) date.clone();
long time = (newDate.getTime() / 1000) + 60 * 60 * 24;
newDate.setTime(time * 1000);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
newDate = format.parse(format.format(newDate));
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
return newDate;
}
示例2: getReservations
import java.util.Date; //导入方法依赖的package包/类
@RequestMapping(value = Mappings.RESERVATIONS_JSON_GET, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public List<Reservation> getReservations(
@RequestParam(value = "start", required = true) String startDateStr,
@RequestParam(value = "end", required = true) String endDateStr,
@RequestParam(value = "accommodation", required = false, defaultValue = "-1")
Long accommodationId) throws Exception {
Date startDate = Utils.stringToDateTime(startDateStr, "dd/MM/YYYY HH:mm").toDate();
Date endDate = Utils.stringToDateTime(endDateStr, "dd/MM/YYYYYY HH:mm").toDate();
if (startDate.getTime() > endDate.getTime()) {
throw new IllegalArgumentException("Begin date is greater than end date: " + startDateStr + " / " + endDateStr);
}
List<Reservation> result;
if (accommodationId != -1) {
result = reservationService.getByInterval(startDate, endDate, true, accommodationId);
} else {
result = reservationService.getByInterval(startDate, endDate, true);
}
return result;
}
示例3: getTimestampString
import java.util.Date; //导入方法依赖的package包/类
public static String getTimestampString(Date date) {
String tamp = null;
String var2 = Locale.getDefault().getLanguage();
boolean isZh = var2.startsWith("zh");
long time = date.getTime();
if(isSameDay(time)) {
if(isZh) {
tamp = "aa hh:mm";
} else {
tamp = "hh:mm aa";
}
} else if(isYesterday(time)) {
if(!isZh) {
return "Yesterday " + (new SimpleDateFormat("hh:mm aa", Locale.ENGLISH)).format(date);
}
tamp = "昨天aa hh:mm";
} else if(isZh) {
tamp = "M月d日aa hh:mm";
} else {
tamp = "MMM dd hh:mm aa";
}
return isZh?(new SimpleDateFormat(tamp, Locale.CHINESE)).format(date)
:(new SimpleDateFormat(tamp, Locale.ENGLISH)).format(date);
}
示例4: get
import java.util.Date; //导入方法依赖的package包/类
@GET
@Produces(MediaType.APPLICATION_JSON)
public static Response get(
@QueryParam("time") Date time,
@QueryParam("version") TransactionId.W version
) throws ApiException {
log.debug("[handle] dto-changes");
try {
TransactionId.W targetTx = version != null ? version : TransactionContext.getLastCommittedTransactionId();
Long targetTime = time != null ? time.getTime() : null;
DtoChanges dtoChanges = DtoChangesSpawner.getDtoChanges(targetTx);
try (AutoCloseableTx tx = AutoCloseableTx.beginTx(targetTime, targetTx)) {
return Response.ok(Responses.json.format(DtoChangesSpawner.toMap(dtoChanges)), MediaType.APPLICATION_JSON_TYPE).build();
}
} catch (RemoteException e) {
throw new InternalServerError("NAEF-00500", "NAEF通信エラー. RMI接続失敗.");
}
}
示例5: popConnection
import java.util.Date; //导入方法依赖的package包/类
/**
* Pops a connection from the pool and checks if it is open and the last
* used time is below 19 minutes. If those things are false, it attempts to
* close the connection. Otherwise it returns the connection or simply
* instantiates a new one;
*
* @return
* @throws SQLException
*/
public synchronized Connection popConnection() throws SQLException {
if (this.transaction_connection != null)
return this.transaction_connection;
else if (!connection_pool.isEmpty()) {
Connection conn = connection_pool.removeFirst();
Date conn_used = connection_last_used.removeFirst();
if (!conn.isClosed()) {
// 19 minutes threshold
if (new Date().getTime() - conn_used.getTime() <= 1140000)
return conn;
// just close it and do nothing
try {
conn.close();
} catch (Exception e) {
}
} // try to pop another one;
return popConnection();
}
return properties == null
? DriverManager.getConnection(url)
: DriverManager.getConnection(url, properties);
}
示例6: shouldGetCatWithCustomDate_after
import java.util.Date; //导入方法依赖的package包/类
@Test
public void shouldGetCatWithCustomDate_after() {
//given
Date now = new Date(System.currentTimeMillis());
Cat cat1 = new Cat("Java", new Date(now.getTime() - 60 * 1000 * 1000));
Cat cat2 = new Cat("Blob", new Date(now.getTime() + 60 * 1000 * 1000));
//when
carEntityManager.add(cat1).subscribe();
carEntityManager.add(cat2).subscribe();
List<Cat> cats = carEntityManager.select().date().after(now).asObservable().blockingFirst();
//then
assertThat(cats).hasSize(1);
assertThat(cats.get(0).getShortName()).isEqualTo("Blob");
}
示例7: toString
import java.util.Date; //导入方法依赖的package包/类
@Override
public String toString()
{
Date current_date = new Date();
UserQuotas user_quotas = this.getUserQuotas();
String quotas_message =
(user_quotas != null ? user_quotas.toString() : "User Quotas: none");
String avg_bandwidth = "Average bandwidth: -- undetermined --";
if (this.firstPermitDate != null)
{
long delay = current_date.getTime() - this.firstPermitDate.getTime();
if (delay > 0)
{
avg_bandwidth =
"Average bandwidth: "
+ (8000 * this.totalAcquiredPermits
/ ((current_date.getTime() -
this.firstPermitDate.getTime()) * 1048576)) + " Mbit/s";
}
else
{
avg_bandwidth = "Average bandwidth: -- transfer delay too small --";
}
}
return "Channel Flow ("
+ ((this.getName() != null) ? this.getName() : "--anonymous--")
+ " x " + this.getWeight() + ") - " + quotas_message + " - "
+ avg_bandwidth;
}
示例8: selectCountByDeviceAndSensor
import java.util.Date; //导入方法依赖的package包/类
@Override
public Status selectCountByDeviceAndSensor(String deviceCode, String sensorCode, Date startTime, Date endTime) {
long costTime = 0L;
Cluster cluster = null;
try {
cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
Session session = cluster.connect(KEY_SPACE_NAME);
String selectCql = "SELECT COUNT(*) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
+ " ALLOW FILTERING";
// System.out.println(selectCql);
long startTime1 = System.nanoTime();
ResultSet rs = session.execute(selectCql);
long endTime1 = System.nanoTime();
costTime = endTime1 - startTime1;
} finally {
if (cluster != null)
cluster.close();
}
// System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
return Status.OK(costTime);
}
示例9: convertDateToMills
import java.util.Date; //导入方法依赖的package包/类
private long convertDateToMills(String dateString) {
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm", Locale.getDefault());
Date date = null;
try {
date = sdf.parse(dateString);
} catch (ParseException ex) {
ex.printStackTrace();
}
return date.getTime();
}
示例10: getYesterday
import java.util.Date; //导入方法依赖的package包/类
public static Date getYesterday() {
Date date = new Date();
long time = (date.getTime() / 1000) - 60 * 60 * 24;
date.setTime(time * 1000);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try {
date = format.parse(format.format(date));
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
return date;
}
示例11: getTimeShowRentString
import java.util.Date; //导入方法依赖的package包/类
public static String getTimeShowRentString(long milliseconds) {
String dataString;
String timeStringBy24;
Date currentTime = new Date(milliseconds);
Date today = new Date();
Calendar todayStart = Calendar.getInstance();
todayStart.set(Calendar.HOUR_OF_DAY, 0);
todayStart.set(Calendar.MINUTE, 0);
todayStart.set(Calendar.SECOND, 0);
todayStart.set(Calendar.MILLISECOND, 0);
Date todaybegin = todayStart.getTime();
Date tomorrowBegin = new Date(todaybegin.getTime() + 3600 * 24 * 1000);
Date lastdaybegin = new Date(tomorrowBegin.getTime() + 3600 * 24 * 1000);// 后天
Date last_daybegin = new Date(lastdaybegin.getTime() + 3600 * 24 * 1000);// 大后天
SimpleDateFormat dateformatter2 = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
dataString = dateformatter2.format(currentTime);
if (currentTime.after(last_daybegin)) {
dataString = dateformatter2.format(currentTime);
} else if (currentTime.after(lastdaybegin)) {
dataString += " 后天";
} else if (currentTime.after(tomorrowBegin)) {
dataString += " 明天";
} else if (currentTime.after(todaybegin)) {
dataString += " 今天";
} else {
dataString = dateformatter2.format(currentTime);
}
return dataString /*+ " " + timeStringBy24*/;
}
示例12: checkCondition
import java.util.Date; //导入方法依赖的package包/类
/**
* Check the food condition for that storage.
* @param food - Food
* @return yes or not
*/
@Override
public boolean checkCondition(Food food) {
Date dateNow = new Date();
return (((double) (dateNow.getTime() - food.getCreateDate().getTime())
/ (double) (food.getExpireDate().getTime() - food.getCreateDate().getTime())) < LVL);
}
示例13: checkRough
import java.util.Date; //导入方法依赖的package包/类
static void checkRough(Date t, int duration) throws Exception {
Date now = new Date();
if (t == null && duration == -1) {
return;
}
long change = (t.getTime() - System.currentTimeMillis()) / 1000;
if (change > duration + 20 || change < duration - 20) {
throw new Exception(t + " is not " + duration);
}
}
示例14: setCreated
import java.util.Date; //导入方法依赖的package包/类
@Override
public IEvent setCreated(final Date created) {
this.created = new Date(created.getTime());
return this;
}
示例15: a
import java.util.Date; //导入方法依赖的package包/类
public final /* synthetic */ Object a(a aVar) {
Date date = (Date) this.a.a(aVar);
return date != null ? new Timestamp(date.getTime()) : null;
}