本文整理了Java中java.util.Calendar.setTimeZone()
方法的一些代码示例,展示了Calendar.setTimeZone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.setTimeZone()
方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:setTimeZone
[英]Sets the TimeZone used by this Calendar.
[中]
代码示例来源:origin: looly/hutool
/**
* {@inheritDoc}
*/
@Override
void setCalendar(final FastDateParser parser, final Calendar cal, final String value) {
if (value.equals("Z")) {
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
} else {
cal.setTimeZone(TimeZone.getTimeZone("GMT" + value));
}
}
代码示例来源: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: stackoverflow.com
//instantiates a calendar using the current time in the specified timezone
Calendar cSchedStartCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
//change the timezone
cSchedStartCal.setTimeZone(TimeZone.getTimeZone("Asia/Calcutta"));
//get the current hour of the day in the new timezone
cSchedStartCal.get(Calendar.HOUR_OF_DAY);
代码示例来源:origin: groovy/groovy-core
private static Date internalDate(TimeZone tz, int year, int month, int day, int hour, int minute, int second) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, second);
calendar.setTimeZone(tz);
return calendar.getTime();
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Converts Java time to NTFS time.
* @param date the Java time
* @return the NTFS time
*/
public static long javaTimeToNtfsTime(final Date date) {
final Calendar ntfsEpoch = Calendar.getInstance();
ntfsEpoch.setTimeZone(TimeZone.getTimeZone("GMT+0"));
ntfsEpoch.set(1601, 0, 1, 0, 0, 0);
ntfsEpoch.set(Calendar.MILLISECOND, 0);
return ((date.getTime() - ntfsEpoch.getTimeInMillis())* 1000 * 10);
}
}
代码示例来源:origin: quartz-scheduler/quartz
long repeatLong = getRepeatInterval();
Calendar aTime = Calendar.getInstance();
aTime.setTime(afterTime);
Calendar sTime = Calendar.getInstance();
if(timeZone != null)
sTime.setTimeZone(timeZone);
sTime.setTime(getStartTime());
sTime.setLenient(true);
jumpCount++;
sTime.add(Calendar.SECOND, getRepeatInterval() * (int)jumpCount);
time = sTime.getTime();
jumpCount++;
sTime.add(Calendar.MINUTE, getRepeatInterval() * (int)jumpCount);
time = sTime.getTime();
jumpCount++;
sTime.add(Calendar.HOUR_OF_DAY, getRepeatInterval() * (int)jumpCount);
time = sTime.getTime();
代码示例来源:origin: quartz-scheduler/quartz
/**
* Create a TimeOfDay from the given date (at the zero-second), in the system default TimeZone.
*
* @param dateTime The java.util.Date from which to extract Hour and Minute.
* @param tz The TimeZone from which relate Hour and Minute for the given date. If null, system default
* TimeZone will be used.
*/
public static TimeOfDay hourAndMinuteFromDate(Date dateTime, TimeZone tz) {
if (dateTime == null)
return null;
Calendar cal = Calendar.getInstance();
cal.setTime(dateTime);
if(tz != null)
cal.setTimeZone(tz);
return new TimeOfDay(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
}
代码示例来源:origin: wildfly/wildfly
String time = timeFraction[0];
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(0);
calendar.setLenient(false);
calendar.set(Calendar.YEAR, Integer.parseInt(time.substring(0, 4)));
calendar.set(Calendar.MONTH, Integer.parseInt(time.substring(4, 6)) - 1);
calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(time.substring(6, 8)));
calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.substring(8, 10)));
if (time.length() >= 12) calendar.set(Calendar.MINUTE, Integer.parseInt(time.substring(10, 12)));
char delimiter = generalized.charAt(parts[0].length());
if (delimiter == 'Z') {
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
} else {
calendar.setTimeZone(TimeZone.getTimeZone("GMT" + delimiter + parts[1]));
return calendar.getTime();
代码示例来源:origin: primefaces/primefaces
String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
String clientId = getClientId(context);
TimeZone tz = CalendarUtils.calculateTimeZone(this.getTimeZone(), TimeZone.getTimeZone("UTC"));
int minuteDelta = Double.valueOf(params.get(clientId + "_minuteDelta")).intValue();
Calendar calendar = Calendar.getInstance();
calendar.setTime(movedEvent.getStartDate());
calendar.setTimeZone(tz);
calendar.add(Calendar.DATE, dayDelta);
calendar.add(Calendar.MINUTE, minuteDelta);
movedEvent.getStartDate().setTime(calendar.getTimeInMillis());
calendar = Calendar.getInstance();
calendar.setTime(movedEvent.getEndDate());
calendar.setTimeZone(tz);
calendar.add(Calendar.DATE, dayDelta);
calendar.add(Calendar.MINUTE, minuteDelta);
Calendar calendar = Calendar.getInstance();
calendar.setTime(resizedEvent.getEndDate());
calendar.setTimeZone(tz);
calendar.add(Calendar.DATE, dayDelta);
calendar.add(Calendar.MINUTE, minuteDelta);
代码示例来源:origin: spring-projects/spring-framework
calendar.setTimeZone(this.timeZone);
calendar.setTime(date);
calendar.set(Calendar.MILLISECOND, 0);
long originalTimestamp = calendar.getTimeInMillis();
doNext(calendar, calendar.get(Calendar.YEAR));
return calendar.getTime();
代码示例来源:origin: stackoverflow.com
Calendar calendar = Calendar.getInstance();
TimeZone fromTimeZone = calendar.getTimeZone();
TimeZone toTimeZone = TimeZone.getTimeZone("CST");
calendar.setTimeZone(fromTimeZone);
calendar.add(Calendar.MILLISECOND, fromTimeZone.getRawOffset() * -1);
if (fromTimeZone.inDaylightTime(calendar.getTime())) {
calendar.add(Calendar.MILLISECOND, calendar.getTimeZone().getDSTSavings() * -1);
}
calendar.add(Calendar.MILLISECOND, toTimeZone.getRawOffset());
if (toTimeZone.inDaylightTime(calendar.getTime())) {
calendar.add(Calendar.MILLISECOND, toTimeZone.getDSTSavings());
}
System.out.println(calendar.getTime());
代码示例来源:origin: com.alibaba/fastjson
long millis = Long.parseLong(numberText);
calendar = Calendar.getInstance(timeZone, locale);
calendar.setTimeInMillis(millis);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, seconds);
calendar.set(Calendar.MILLISECOND, millis);
String[] timeZoneIDs = TimeZone.getAvailableIDs(0);
if (timeZoneIDs.length > 0) {
TimeZone timeZone = TimeZone.getTimeZone(timeZoneIDs[0]);
calendar.setTimeZone(timeZone);
String[] timeZoneIDs = TimeZone.getAvailableIDs(0);
if (timeZoneIDs.length > 0) {
TimeZone timeZone = TimeZone.getTimeZone(timeZoneIDs[0]);
calendar.setTimeZone(timeZone);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void dateOtherLocale() {
Locale defaultLocale = Locale.getDefault();
try {
Locale.setDefault(new Locale("nl", "nl"));
Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20);
calendar.setTimeZone(TimeZone.getTimeZone("CET"));
long date = calendar.getTimeInMillis();
headers.setDate(date);
assertEquals("Invalid Date header", "Thu, 18 Dec 2008 10:20:00 GMT", headers.getFirst("date"));
assertEquals("Invalid Date header", date, headers.getDate());
}
finally {
Locale.setDefault(defaultLocale);
}
}
代码示例来源:origin: geoserver/geoserver
public void testReducedAccuracyMilliseconds() throws Exception {
Calendar c = new GregorianCalendar();
c.setTimeZone(TimeParser.UTC_TZ);
c.clear();
c.set(Calendar.YEAR, 2000);
c.set(Calendar.MONTH, 3); // 0-indexed
c.set(Calendar.DAY_OF_MONTH, 4);
c.set(Calendar.HOUR_OF_DAY, 12);
assertEquals(instant, c.getTime());
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 60);
assertEquals(instant, c.getTime());
c.set(Calendar.MINUTE, 15);
c.set(Calendar.MILLISECOND, 123);
assertEquals(instant, c.getTime());
代码示例来源:origin: stackoverflow.com
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Asia/Tokyo"))
cal.set(Calendar.HOUR_OF_DAY, 15) //15:00 in Tokyo
cal.set(Calendar.MONTH, Calendar.NOVEMBER)
cal.setTimeZone(TimeZone.getTimeZone("Australia/Melbourne"))
cal.get(Calendar.HOUR_OF_DAY) //17:00 in Melbourne
代码示例来源:origin: opentripplanner/OpenTripPlanner
/**
* Constructs a {@link Calendar} object such that the Calendar will be at
* "midnight" (12:00am) at the start of the day specified by this service date
* and the target timezone. Note that we take the GTFS convention of
* calculating midnight by setting the target date to noon (12:00pm) for the
* service date and timezone specified and then subtracting twelve hours.
* Normally that would be equivalent to midnight, except on Daylight Saving
* Time days, in which case it can be an hour ahead or behind. This behavior
* ensures correct calculation of {@link StopTime} arrival and departure time
* when the second offset is added to the localized service date.
*
* @param timeZone the target timezone to localize the service date to
* @return a localized date at "midnight" at the start of this service date in
* the specified timezone
*/
public Calendar getAsCalendar(TimeZone timeZone) {
Calendar c = Calendar.getInstance();
c.setTimeZone(timeZone);
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month - 1);
c.set(Calendar.DAY_OF_MONTH, day);
moveCalendarToServiceDate(c);
return c;
}
代码示例来源:origin: DozerMapper/dozer
result.setTime((java.util.Date)srcObj);
} else if (Calendar.class.isAssignableFrom(srcFieldClass)) {
result.setTime(c.getTime());
result.setTimeZone(c.getTimeZone());
} else if (XMLGregorianCalendar.class.isAssignableFrom(srcFieldClass)) {
Calendar c = ((XMLGregorianCalendar)srcObj).toGregorianCalendar();
result.setTime(c.getTime());
result.setTimeZone(c.getTimeZone());
} else if (dateFormat != null && String.class.isAssignableFrom(srcFieldClass)) {
return dateFormat.format(result.getTime());
代码示例来源:origin: alibaba/fastjson
return (T) calendar.getTime();
if (index > 20) {
String tzStr = strVal.substring(index + 1);
TimeZone timeZone = TimeZone.getTimeZone(tzStr);
if (!"GMT".equals(timeZone.getID())) {
String subStr = strVal.substring(0, index);
Calendar calendar = dateLexer.getCalendar();
calendar.setTimeZone(timeZone);
return (T) calendar.getTime();
代码示例来源:origin: wildfly/wildfly
nextCal.setTimeZone(this.timezone);
Date start = this.scheduleExpression.getStart();
if (start != null && currentCal.getTime().before(start)) {
nextCal.setTime(start);
} else {
if (increment) {
代码示例来源:origin: igniterealtime/Openfire
public String format(Date date) {
Calendar c = new GregorianCalendar(cDefaultTimeZone);
c.setTime(date);
if (mTimeZone != null) {
c.setTimeZone(mTimeZone);
}
return applyRules(c, new StringBuffer(mMaxLengthEstimate)).toString();
}
内容来源于网络,如有侵权,请联系作者删除!