本文整理了Java中java.util.TimeZone.getTimeZone()
方法的一些代码示例,展示了TimeZone.getTimeZone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TimeZone.getTimeZone()
方法的具体详情如下:
包路径:java.util.TimeZone
类名称:TimeZone
方法名:getTimeZone
[英]Gets the TimeZone
for the given ID.
[中]获取给定ID的TimeZone
。
代码示例来源:origin: jenkinsci/jenkins
private static String clientDateString() {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
df.setTimeZone(tz); // strip timezone
return df.format(new Date());
}
代码示例来源:origin: alibaba/canal
public final String formatUTCTZ(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.format(date);
}
代码示例来源:origin: stackoverflow.com
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = isoFormat.parse("2010-05-23T09:01:02");
代码示例来源:origin: apache/rocketmq
public String getCurTime() {
String fromTimeZone = "GMT+8";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
format.setTimeZone(TimeZone.getTimeZone(fromTimeZone));
String chinaDate = format.format(date);
return chinaDate;
}
代码示例来源:origin: org.testng/testng
static String timeAsGmt() {
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
sdf.applyPattern("dd MMM yyyy HH:mm:ss z");
return sdf.format(Calendar.getInstance().getTime());
}
代码示例来源:origin: square/moshi
private Date newDate(int year, int month, int day, int hour, int offset) {
Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
calendar.set(year, month - 1, day, hour, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
return new Date(calendar.getTimeInMillis() - TimeUnit.HOURS.toMillis(offset));
}
}
代码示例来源:origin: stackoverflow.com
TimeZone tz = TimeZone.getTimeZone("<local-time-zone>");
//...
Date dateValue = rs.getDate("DateColumn");
Calendar calValue = Calendar.getInstance(tz);
calValue.setTime(dateValue);
代码示例来源:origin: knowm/XChange
@Override
public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
final String dateTimeInUnixFormat = p.getText();
try {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.setTimeInMillis(Long.parseLong(dateTimeInUnixFormat + "000"));
return calendar.getTime();
} catch (Exception e) {
return new Date(0);
}
}
}
代码示例来源:origin: apache/groovy
@Test
public void calendarConversionsDifferingTimeZones() throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmmss SSS");
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC+0"));
calendar.setTime(sdf.parse("20180115 153256 001"));
}
代码示例来源:origin: log4j/log4j
public
void activateOptions() {
setDateFormat(dateFormatOption);
if(timeZoneID != null && dateFormat != null) {
dateFormat.setTimeZone(TimeZone.getTimeZone(timeZoneID));
}
}
代码示例来源:origin: stackoverflow.com
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
//Local time zone
SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
//Time in GMT
return dateFormatLocal.parse( dateFormatGmt.format(new Date()) );
代码示例来源:origin: knowm/XChange
public static Date stringToDate(String dateString) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.parse(dateString);
} catch (ParseException e) {
return new Date(0);
}
}
代码示例来源:origin: alibaba/Sentinel
private SimpleDateFormat createSimpleDateFormat() {
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
fmt.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
return fmt;
}
}
代码示例来源:origin: TooTallNate/Java-WebSocket
/**
* Generate a date for for the date-header
*
* @return the server time
*/
private String getServerTime() {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss z", Locale.US );
dateFormat.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
return dateFormat.format( calendar.getTime() );
}
代码示例来源:origin: spring-projects/spring-framework
@Parameters(name = "date [{0}], time zone [{1}]")
public static List<Object[]> getParameters() {
List<Object[]> list = new ArrayList<>();
list.add(new Object[] { new Date(), TimeZone.getTimeZone("PST") });
list.add(new Object[] { new Date(), TimeZone.getTimeZone("CET") });
return list;
}
代码示例来源:origin: robolectric/robolectric
private Calendar getCalendar() {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone(time.timezone));
c.set(time.year, time.month, time.monthDay, time.hour, time.minute, time.second);
c.set(Calendar.MILLISECOND, 0);
return c;
}
}
代码示例来源:origin: stackoverflow.com
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
代码示例来源:origin: eugenp/tutorials
protected void init() {
// Use RFC3339 format for date and datetime.
// See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14
this.dateFormat = new RFC3339DateFormat();
// Use UTC as the default time zone.
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
// Set default User-Agent.
setUserAgent("Java-SDK");
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, Authentication>();
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
authentications.put("petstore_auth", new OAuth());
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}
代码示例来源:origin: stackoverflow.com
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
df.setTimeZone(tz);
String nowAsISO = df.format(new Date());
代码示例来源:origin: knowm/XChange
public static Date stringToDate(String dateString) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
return sdf.parse(dateString);
} catch (ParseException e) {
return new Date(0);
}
}
内容来源于网络,如有侵权,请联系作者删除!