本文整理匯總了Java中java.util.Date.setTime方法的典型用法代碼示例。如果您正苦於以下問題:Java Date.setTime方法的具體用法?Java Date.setTime怎麽用?Java Date.setTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Date
的用法示例。
在下文中一共展示了Date.setTime方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDate
import java.util.Date; //導入方法依賴的package包/類
@Override
public Date getDate(int columnIndex) throws ParseException {
final Cell cell = getCurrentCell(columnIndex);
if (cell.getType() == CellType.DATE || cell.getType() == CellType.DATE_FORMULA) {
Date date = ((DateCell) cell).getDate();
// hack to get actual date written in excel sheet. converts date to UTC
int offset = TimeZone.getDefault().getOffset(date.getTime());
date.setTime(date.getTime() - offset);
return date;
} else {
String valueString = cell.getContents();
try {
return dateFormatProvider.geDateFormat().parse(valueString);
} catch (java.text.ParseException e) {
throw new ParseException(
new ParsingError(currentRow, columnIndex, ParsingError.ErrorCode.UNPARSEABLE_DATE, valueString));
}
}
}
示例2: fillBuckets2
import java.util.Date; //導入方法依賴的package包/類
public static List<VaultEntry> fillBuckets2(List<VaultEntry> liste) {
List<VaultEntry> blah = new ArrayList<>();
long last = liste.get(liste.size() - 1).getTimestamp().getTime();
int i = 0;
while (liste.get(i).getTimestamp().getTime() < last) {
Date tempDate1 = liste.get(i).getTimestamp();
Date tempDate2 = liste.get(i + 1).getTimestamp();
int times = Math.round(((tempDate2.getTime() - tempDate1.getTime()) / 60000));
if (times > 0) {
for (int j = 0; j < times - 1; j++) {
tempDate1.setTime(tempDate1.getTime() + 60000);
VaultEntry empty = new VaultEntry(VaultEntryType.BOLUS_SQARE, TimestampUtils.createCleanTimestamp(tempDate1));
blah.add(empty);
// System.out.println(empty);
}
}
i = i + 1;
}
return blah;
}
示例3: main
import java.util.Date; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
byte[] asn1Bytes = "asn1".getBytes();
KerberosPrincipal client = new KerberosPrincipal("client");
KerberosPrincipal server = new KerberosPrincipal("server");
byte[] keyBytes = "sessionKey".getBytes();
long originalTime = 12345678L;
Date inDate = new Date(originalTime);
boolean[] flags = new boolean[9];
flags[8] = true; // renewable
KerberosTicket t = new KerberosTicket(asn1Bytes, client, server,
keyBytes, 1 /*keyType*/, flags, inDate /*authTime*/,
inDate /*startTime*/, inDate /*endTime*/,
inDate /*renewTill*/, null /*clientAddresses*/);
inDate.setTime(0); // for testing the constructor
testDateImmutability(t, originalTime);
testS11nCompatibility(t); // S11n: Serialization
testDestroy(t);
}
示例4: getPrazo
import java.util.Date; //導入方法依賴的package包/類
public int getPrazo (){
Date entrega = new Date();
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
try{
entrega = format.parse(this.getDataEntrega());
}
catch (ParseException e) {
e.printStackTrace();
}
Date hoje = new Date();
int prazo = 0;
while (entrega.after(hoje)) {
prazo++;
hoje.setTime(hoje.getTime() + 86400000);
}
return prazo;
}
示例5: generateToken
import java.util.Date; //導入方法依賴的package包/類
private String generateToken(byte[] secretBytes, Claims claims, User user, long expiresInMillis) {
DefaultJwsHeader jwsHeader = new DefaultJwsHeader();
Date now = new Date();
Date expiresAt = new Date();
jwsHeader.setAlgorithm(signatureAlgorithm.getValue());
jwsHeader.setType(Header.JWT_TYPE);
expiresAt.setTime(now.getTime() + expiresInMillis);
claims.setIssuedAt(now);
claims.setSubject(user.getUsername());
claims.setIssuer(Biliomi.class.getSimpleName());
claims.setExpiration(expiresAt);
claims.put(CLAIMS_CHANNEL, channelName);
claims.put(CLAIMS_USER_DISPLAY_NAME, user.getDisplayName());
JwtBuilder builder = Jwts.builder()
.setHeader((Map<String, Object>) jwsHeader)
.setClaims(claims)
.signWith(signatureAlgorithm, secretBytes);
return builder.compact();
}
示例6: dateAdd
import java.util.Date; //導入方法依賴的package包/類
/**
* 增加時間
*
* @param interval
* [INTERVAL_DAY,INTERVAL_WEEK,INTERVAL_MONTH,INTERVAL_YEAR, INTERVAL_HOUR,INTERVAL_MINUTE]
* @param date
* @param n
* 可以為負數
* @return
*/
public static Date dateAdd(int interval, Date date, int n) {
long time = (date.getTime() / 1000); // 單位秒
switch (interval) {
case INTERVAL_DAY:
time = time + n * 86400;// 60 * 60 * 24;
break;
case INTERVAL_WEEK:
time = time + n * 604800;// 60 * 60 * 24 * 7;
break;
case INTERVAL_MONTH:
time = time + n * 2678400;// 60 * 60 * 24 * 31;
break;
case INTERVAL_YEAR:
time = time + n * 31536000;// 60 * 60 * 24 * 365;
break;
case INTERVAL_HOUR:
time = time + n * 3600;// 60 * 60 ;
break;
case INTERVAL_MINUTE:
time = time + n * 60;
break;
case INTERVAL_SECOND:
time = time + n;
break;
default:
}
Date result = new Date();
result.setTime(time * 1000);
return result;
}
示例7: queryLog
import java.util.Date; //導入方法依賴的package包/類
public List<PTLogBean> queryLog(int priority, Date begin, Date end, int limit) {
SQLiteDatabase db = null;
List<PTLogBean> logList = new ArrayList<PTLogBean>();
try {
db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(String.format("SELECT * FROM %s WHERE %s>=? AND %s>=? AND %s<? ORDER BY %s DESC LIMIT ?", TABLE_NAME, COLUMN_LEVEL, COLUMN_DATE, COLUMN_DATE, COLUMN_DATE),
new String[]{
Integer.toString(priority),
Long.toString(begin.getTime()),
Long.toString(end.getTime()),
Integer.toString(limit)
}
);
while (cursor.moveToNext()) {
PTLogBean logBean = new PTLogBean();
logBean.setLevel(cursor.getInt(cursor.getColumnIndex(PTSqliteHelper.COLUMN_LEVEL)));
logBean.setContent(cursor.getString(cursor.getColumnIndex(PTSqliteHelper.COLUMN_CONTENT)));
String dateString = cursor.getString(cursor.getColumnIndex(PTSqliteHelper.COLUMN_DATE));
Date date = new Date();
date.setTime(Long.parseLong(dateString));
logBean.setDate(date);
logList.add(logBean);
}
} catch (SQLException ex) {
return logList;
}
// reverse
List<?> shallowCopy = logList.subList(0, logList.size());
Collections.reverse(shallowCopy);
return logList;
}
示例8: getYesterday
import java.util.Date; //導入方法依賴的package包/類
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;
}
示例9: getWeekAgo
import java.util.Date; //導入方法依賴的package包/類
public static Date getWeekAgo() {
Date date = new Date();
long time = (date.getTime() / 1000) - 7 * 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;
}
示例10: dateAdd
import java.util.Date; //導入方法依賴的package包/類
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;
}
示例11: testSetDate
import java.util.Date; //導入方法依賴的package包/類
@Test
public void testSetDate() {
Date date = new Date();
mField.setDate(date);
assertThat(mField.getDate()).isEqualTo(date);
date.setTime(date.getTime() + 86400000);
mField.setTime(date.getTime());
assertThat(mField.getDate()).isEqualTo(date);
assertThat(mField.setFromString("2017-03-23")).isTrue();
assertThat(mField.getLocalizedDateString()).isEqualTo("2017-03-23");
}
示例12: run
import java.util.Date; //導入方法依賴的package包/類
/**
* Main method of the task. It generates 100 events with the same activation
* time. The activation time will be the execution time of the thread plus
* the id of the thread seconds
*/
@Override
public void run() {
Date now = new Date();
Date delay = new Date();
delay.setTime(now.getTime() + (id * 1000));
System.out.printf("Thread %s: %s\n", id, delay);
for (int i = 0; i < 100; i++) {
Event event = new Event(delay);
queue.add(event);
}
}
示例13: addTo
import java.util.Date; //導入方法依賴的package包/類
/**
* Adds this duration to a {@link Date} object.
*
* <p>
* The given date is first converted into
* a {@link java.util.GregorianCalendar}, then the duration
* is added exactly like the {@link #addTo(Calendar)} method.
*
* <p>
* The updated time instant is then converted back into a
* {@link Date} object and used to update the given {@link Date} object.
*
* <p>
* This somewhat redundant computation is necessary to unambiguously
* determine the duration of months and years.
*
* @param date
* A date object whose value will be modified.
* @throws NullPointerException
* if the date parameter is null.
*/
public void addTo(Date date) {
// check data parameter
if (date == null) {
throw new NullPointerException(
"Cannot call "
+ this.getClass().getName()
+ "#addTo(Date date) with date == null."
);
}
Calendar cal = new GregorianCalendar();
cal.setTime(date);
this.addTo(cal);
date.setTime(getCalendarTimeInMillis(cal));
}
示例14: findPosition
import java.util.Date; //導入方法依賴的package包/類
private long findPosition(File file, Date date) throws IOException {
RandomAccessFile raf = new RandomAccessFile(file, "r");
try {
Date cur_date = extractDate(raf);
if (cur_date != null) {
int compare = date.compareTo(cur_date);
if (compare > 0) {
date.setTime(date.getTime() - 1);
long min = raf.getFilePointer();
long max = raf.length();
Date last_date = null;
long last_pos = 0;
while (cur_date != null && !cur_date.equals(last_date) && !cur_date.equals(date)) {
last_date = cur_date;
last_pos = raf.getFilePointer();
long cur = min + ((max - min) / 2);
raf.seek(cur);
cur_date = extractDate(raf);
if (cur_date == null || date.compareTo(cur_date) < 0) {
max = cur;
} else {
min = cur;
}
}
date.setTime(date.getTime() + 1);
if (cur_date != null && date.compareTo(cur_date) < 0) {
raf.seek(min);
cur_date = extractDate(raf);
}
// Fix #1788 : 'Out of range Date' exception when start date is 2011-01-25 12:32 for log file of #1787
// can find next cur_date but last_date is a valid candidate for the end date
if (cur_date == null && last_date != null) {
cur_date = last_date;
raf.seek(last_pos);
}
while (cur_date != null && date.compareTo(cur_date) > 0) {
raf.skipBytes(1);
cur_date = extractDate(raf);
}
}
if (cur_date != null) {
return raf.getFilePointer();
}
}
throw new IOException("Out of range Date");
} finally {
raf.close();
}
}
示例15: convertDateLine
import java.util.Date; //導入方法依賴的package包/類
@SuppressLint("SimpleDateFormat")
public static Date convertDateLine (String dateLine) {
// TODO: Finish it.
try {
Logger.i(TAG, "formatDate");
return new SimpleDateFormat("yyyy-MM-dd k:m:s")
.parse(dateLine);
} catch (ParseException e) {
Logger.i(TAG, "try match 7 天前");
// 7 天前
Matcher matcher = Pattern.compile("\\d+ 天前").matcher(dateLine);
if (matcher.matches()) {
Logger.i(TAG, "7 天前 matches");
if (matcher.find()) {
Logger.i(TAG, "7 天前 find");
int days = Integer.parseInt(dateLine.substring(matcher.start()
, matcher.end()));
return getDateBefore(new Date(), days);
}
} else {
Logger.i(TAG, "try match 昨天 23:01");
// 昨天 23:01
Matcher m1 = Pattern.compile("昨天 \\d+:\\d+").matcher(dateLine);
if (m1.matches()) {
Logger.i(TAG, "昨天 23:01 matches");
int hour = -1;
int time = -1;
while (m1.find()) {
if (hour == -1) {
hour = Integer.parseInt(dateLine.substring(m1.start()
, m1.end()));
} else if (time == -1) {
time = Integer.parseInt(dateLine.substring(m1.start()
, m1.end()));
} else break;
}
Logger.i(TAG, "昨天 23:01 hour:" + hour + "time:" + time);
Date date = new Date();
date.setHours(hour);
date.setTime(time);
return getDateBefore(date, date.getDay() - 1);
}
}
Logger.e(TAG, "Fail to parse date!", e);
return new Date();
}
}