本文整理匯總了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;
}