本文整理了Java中java.util.Calendar.getTimeZone()
方法的一些代码示例,展示了Calendar.getTimeZone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.getTimeZone()
方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:getTimeZone
[英]Returns the time zone used by this Calendar.
[中]返回此日历使用的时区。
代码示例来源:origin: neo4j/neo4j
private String getLocalTimeZone()
{
TimeZone tz = Calendar.getInstance().getTimeZone();
return tz.getID();
}
},
代码示例来源:origin: spring-projects/spring-framework
private static ZonedDateTime calendarToZonedDateTime(Calendar source) {
if (source instanceof GregorianCalendar) {
return ((GregorianCalendar) source).toZonedDateTime();
}
else {
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(source.getTimeInMillis()),
source.getTimeZone().toZoneId());
}
}
代码示例来源:origin: stackoverflow.com
Calendar cal = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
dateFormat.setTimeZone(cal.getTimeZone());
System.out.println(dateFormat.format(cal.getTime()));
代码示例来源:origin: org.apache.ant/ant
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone();
int offset = tz.getOffset(cal.get(Calendar.ERA),
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.DAY_OF_WEEK),
return DATE_HEADER_FORMAT_INT.format(cal.getTime()) + tzMarker.toString();
代码示例来源:origin: stackoverflow.com
public static Calendar convertToGmt(Calendar cal) {
Date date = cal.getTime();
TimeZone tz = cal.getTimeZone();
log.debug("input calendar has date [" + date + "]");
//Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
long msFromEpochGmt = date.getTime();
//gives you the current offset in ms from GMT at the current date
int offsetFromUTC = tz.getOffset(msFromEpochGmt);
log.debug("offset is " + offsetFromUTC);
//create a new calendar in GMT timezone, set to this date and add the offset
Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
gmtCal.setTime(date);
gmtCal.add(Calendar.MILLISECOND, offsetFromUTC);
log.debug("Created GMT cal with date [" + gmtCal.getTime() + "]");
return gmtCal;
}
代码示例来源:origin: robovm/robovm
private static boolean isThisYear(Calendar c) {
Calendar now = Calendar.getInstance(c.getTimeZone());
return c.get(Calendar.YEAR) == now.get(Calendar.YEAR);
}
代码示例来源:origin: pentaho/pentaho-kettle
Date endDate = metaA.getDate( dataA );
Calendar stDateCal = Calendar.getInstance();
Calendar endDateCal = Calendar.getInstance();
stDateCal.setTime( startDate );
endDateCal.setTime( endDate );
long endL = endDateCal.getTimeInMillis() + endDateCal.getTimeZone().getOffset( endDateCal.getTimeInMillis() );
long startL = stDateCal.getTimeInMillis() + stDateCal.getTimeZone().getOffset( stDateCal.getTimeInMillis() );
long diff = endL - startL;
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* {@inheritDoc}
*/
@Override
public void appendTo(final Appendable buffer, final Calendar calendar) throws IOException {
final TimeZone zone = calendar.getTimeZone();
if (calendar.get(Calendar.DST_OFFSET) == 0) {
buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale));
} else {
buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
}
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
TimeZone tz = calendar.getTimeZone();
try {
calendar.setTimeZone(UTC);
|| dayName == calendar.get(Calendar.DAY_OF_WEEK)) {
calendar.add(Calendar.MINUTE, zone);
return calendar.getTime();
} else {
throw new IllegalArgumentException("Inconsistent day-name");
代码示例来源:origin: wildfly/wildfly
@Override
public void writeObject(ObjectOutput output, Calendar calendar) throws IOException {
output.writeUTF(calendar.getCalendarType());
output.writeLong(calendar.getTimeInMillis());
output.writeBoolean(calendar.isLenient());
output.writeUTF(calendar.getTimeZone().getID());
output.writeInt(calendar.getFirstDayOfWeek());
output.writeInt(calendar.getMinimalDaysInFirstWeek());
}
代码示例来源:origin: wildfly/wildfly
/**
* Returns the last date of the month represented by the passed <code>cal</code>
*
* @param calendar The {@link java.util.Calendar} whose {@link java.util.Calendar#MONTH} field will be used
* as the current month
* @return
*/
public static int getLastDateOfMonth(Calendar calendar) {
Calendar tmpCal = new GregorianCalendar(calendar.getTimeZone());
tmpCal.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
tmpCal.set(Calendar.MONTH, calendar.get(Calendar.MONTH));
tmpCal.set(Calendar.DAY_OF_MONTH, 1);
return tmpCal.getActualMaximum(Calendar.DAY_OF_MONTH);
}
代码示例来源:origin: apache/nifi
@Override
public String toString() {
Calendar expirationTime = Calendar.getInstance();
expirationTime.setTimeInMillis(getExpiration());
long remainingTime = expirationTime.getTimeInMillis() - Calendar.getInstance().getTimeInMillis();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS");
dateFormat.setTimeZone(expirationTime.getTimeZone());
String expirationTimeString = dateFormat.format(expirationTime.getTime());
return new StringBuilder("LoginAuthenticationToken for ")
.append(getName())
.append(" issued by ")
.append(getIssuer())
.append(" expiring at ")
.append(expirationTimeString)
.append(" [")
.append(getExpiration())
.append(" ms, ")
.append(remainingTime)
.append(" ms remaining]")
.toString();
}
代码示例来源:origin: stackoverflow.com
Calendar c = Calendar.getInstance();
System.out.println("current: "+c.getTime());
TimeZone z = c.getTimeZone();
int offset = z.getRawOffset();
if(z.inDaylightTime(new Date())){
offset = offset + z.getDSTSavings();
}
int offsetHrs = offset / 1000 / 60 / 60;
int offsetMins = offset / 1000 / 60 % 60;
System.out.println("offset: " + offsetHrs);
System.out.println("offset: " + offsetMins);
c.add(Calendar.HOUR_OF_DAY, (-offsetHrs));
c.add(Calendar.MINUTE, (-offsetMins));
System.out.println("GMT Time: "+c.getTime());
代码示例来源:origin: apache/hive
@Override
protected TimeZone initialValue() {
return Calendar.getInstance().getTimeZone();
}
};
代码示例来源:origin: org.codehaus.groovy/groovy
@Deprecated
public static String format(Calendar self, String pattern) {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
sdf.setTimeZone(self.getTimeZone());
return sdf.format(self.getTime());
}
代码示例来源:origin: org.apache.ant/ant
/**
* Report locale information
* @param out stream to print to
*/
private static void doReportLocale(PrintStream out) {
//calendar stuff.
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone();
out.println("Timezone "
+ tz.getDisplayName()
+ " offset="
+ tz.getOffset(cal.get(Calendar.ERA), cal.get(Calendar.YEAR), cal
.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal
.get(Calendar.DAY_OF_WEEK), ((cal.get(Calendar.HOUR_OF_DAY)
* MINUTES_PER_HOUR + cal.get(Calendar.MINUTE))
* SECONDS_PER_MINUTE + cal.get(Calendar.SECOND))
* SECONDS_PER_MILLISECOND + cal.get(Calendar.MILLISECOND)));
}
代码示例来源:origin: stackoverflow.com
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, calDate.getTimeInMillis());
values.put(CalendarContract.Events.DTEND, calDate.getTimeInMillis()+60*60*1000);
values.put(CalendarContract.Events.TITLE, this._title);
values.put(CalendarContract.Events.CALENDAR_ID, 1);
values.put(CalendarContract.Events.EVENT_TIMEZONE, Calendar.getInstance()
.getTimeZone().getID());
System.out.println(Calendar.getInstance().getTimeZone().getID());
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
event.put(CalendarContract.Events.DTSTART, calDate.getTimeInMillis());
event.put(CalendarContract.Events.DTEND, calDate.getTimeInMillis()+60*60*1000);
代码示例来源:origin: wildfly/wildfly
private static int getFirstDateInMonthForDayOfWeek(Calendar cal, final int dayOfWeek) {
Calendar tmpCal = new GregorianCalendar(cal.getTimeZone());
tmpCal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
tmpCal.set(Calendar.MONTH, cal.get(Calendar.MONTH));
tmpCal.set(Calendar.DATE, 1);
int day = tmpCal.get(Calendar.DAY_OF_WEEK);
if (day == dayOfWeek) {
return tmpCal.get(Calendar.DATE);
}
while (day != dayOfWeek) {
tmpCal.add(Calendar.DATE, 1);
day = tmpCal.get(Calendar.DAY_OF_WEEK);
}
return tmpCal.get(Calendar.DATE);
}
代码示例来源:origin: org.springframework/spring-context
private static ZonedDateTime calendarToZonedDateTime(Calendar source) {
if (source instanceof GregorianCalendar) {
return ((GregorianCalendar) source).toZonedDateTime();
}
else {
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(source.getTimeInMillis()),
source.getTimeZone().toZoneId());
}
}
代码示例来源:origin: robovm/robovm
/**
* Compares the given object to this {@code Calendar} and returns whether they are
* equal. The object must be an instance of {@code Calendar} and have the same
* properties.
*
* @return {@code true} if the given object is equal to this {@code Calendar}, {@code false}
* otherwise.
*/
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (!(object instanceof Calendar)) {
return false;
}
Calendar cal = (Calendar) object;
return getTimeInMillis() == cal.getTimeInMillis()
&& isLenient() == cal.isLenient()
&& getFirstDayOfWeek() == cal.getFirstDayOfWeek()
&& getMinimalDaysInFirstWeek() == cal.getMinimalDaysInFirstWeek()
&& getTimeZone().equals(cal.getTimeZone());
}
内容来源于网络,如有侵权,请联系作者删除!