本文整理汇总了Java中java.util.TimeZone类的典型用法代码示例。如果您正苦于以下问题:Java TimeZone类的具体用法?Java TimeZone怎么用?Java TimeZone使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TimeZone类属于java.util包,在下文中一共展示了TimeZone类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ApiMedicion
import java.util.TimeZone; //导入依赖的package包/类
public ApiMedicion(Date measuredAt, String currentState, String avisoState, String avisoMaxToday, String escenarioToday, String escenarioTomorrow, String escenarioTomorrowManual, boolean isPureMadrid) {
this.isPureMadrid = isPureMadrid;
MIN_VALUE_PREAVISO = isPureMadrid ? 180 : 140; //180;
MIN_VALUE_AVISO = isPureMadrid ? 200 : 180; //200;
MIN_VALUE_ALERTA = isPureMadrid ? 400 : 300; //400;
this.aviso = currentState;
this.avisoState = avisoState;
this.avisoMaxToday = avisoMaxToday;
this.escenarioStateToday = escenarioToday;
this.escenarioStateTomorrow = escenarioTomorrow;
this.escenarioManualTomorrow = escenarioTomorrowManual;
if (measuredAt == null){
this.measuredAt = null;
} else {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("CET"));
calendar.setTime(measuredAt);
this.measuredAt = calendar;
}
}
示例2: onCreate
import java.util.TimeZone; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_task);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Application application = (Application) getApplication();
mDatabase = application.getDatabase();
if (savedInstanceState != null)
mListId = savedInstanceState.getString(INTENT_LIST_ID);
else
mListId = getIntent().getStringExtra(INTENT_LIST_ID);
Query query = getQuery();
mAdapter = new TaskAdapter(this, query.toLiveQuery());
ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(mAdapter);
setListHeader(listView);
setListItemLongClick(listView);
mDateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
}
示例3: testHourOfDay
import java.util.TimeZone; //导入依赖的package包/类
@Test
public void testHourOfDay() {
TimeZone gmt = TimeZone.getTimeZone("Universal");
Calendar test = Calendar.getInstance(gmt);
test.set(Calendar.YEAR, 1969);
test.set(Calendar.MONTH, Calendar.JULY);
test.set(Calendar.DATE, 20);
test.set(Calendar.HOUR_OF_DAY, 3);
assertEquals(1969, test.get(Calendar.YEAR));
assertEquals(Calendar.JULY, test.get(Calendar.MONTH));
assertEquals(20, test.get(Calendar.DATE));
assertEquals(3, test.get(Calendar.HOUR));
assertEquals(Calendar.AM, test.get(Calendar.AM_PM));
assertEquals(3, test.get(Calendar.HOUR_OF_DAY));
}
示例4: testLoad
import java.util.TimeZone; //导入依赖的package包/类
@Test
public void testLoad() throws Exception {
new ExecuteAsTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC))
.run(() -> assertThat(
load("2017-08-28T07:09:36.000000042Z")
.isEqual(OffsetDateTime.of(2017, 8, 28, 7, 9, 36, 42, ZoneOffset.UTC)),
is(true)
));
}
示例5: withTimeZone
import java.util.TimeZone; //导入依赖的package包/类
/**
* Returns a version of this formatter customized to the provided time zone.
*/
public DateFormatter withTimeZone(TimeZone tz) {
if (!tz.equals(timeZone)) {
return new YMDDateFormatter(requestedFields, localeName, tz);
}
return this;
}
示例6: getDateTimeFromString
import java.util.TimeZone; //导入依赖的package包/类
public static long getDateTimeFromString(String strDate) {
long nTimeNow = 0;
if (strDate == null) {
return 0;
}
try {
SimpleDateFormat myFmt2 = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
myFmt2.setTimeZone(TimeZone.getTimeZone("UTC"));
Date dt = myFmt2.parse(strDate.trim());
nTimeNow = dt.getTime();
} catch (Exception ex) {
}
return nTimeNow;
}
示例7: getBeijingNowTime
import java.util.TimeZone; //导入依赖的package包/类
public static String getBeijingNowTime(String format) {
TimeZone timezone = TimeZone.getTimeZone("Asia/Shanghai");
Date date = new Date(currentTimeMillis());
SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.getDefault());
formatter.setTimeZone(timezone);
return formatter.format(date);
}
示例8: getParser
import java.util.TimeZone; //导入依赖的package包/类
public CompositeFileEntryParser getParser(final String system, final TimeZone zone) {
if(log.isDebugEnabled()) {
log.debug(String.format("Select parser for system %s in zone %s", system, zone));
}
final CompositeFileEntryParser parser;
if(null == zone) {
parser = new FTPParserFactory().createFileEntryParser(system,
TimeZone.getTimeZone(PreferencesFactory.get().getProperty("ftp.timezone.default")));
}
else {
parser = new FTPParserFactory().createFileEntryParser(system, zone);
}
// Configure timezone
parser.configure(null);
return parser;
}
示例9: setTimestampInternal
import java.util.TimeZone; //导入依赖的package包/类
private void setTimestampInternal(int parameterIndex, java.sql.Timestamp x, Calendar targetCalendar, TimeZone tz, boolean rollForward) throws SQLException {
if (x == null) {
setNull(parameterIndex, java.sql.Types.TIMESTAMP);
} else {
BindValue binding = getBinding(parameterIndex, false);
resetToType(binding, MysqlDefs.FIELD_TYPE_DATETIME);
if (!this.sendFractionalSeconds) {
x = TimeUtil.truncateFractionalSeconds(x);
}
if (!this.useLegacyDatetimeCode) {
binding.value = x;
} else {
Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ? this.connection.getUtcCalendar()
: getCalendarInstanceForSessionOrNew();
binding.value = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, x, tz, this.connection.getServerTimezoneTZ(),
rollForward);
}
}
}
示例10: getTimeZoneDisplay
import java.util.TimeZone; //导入依赖的package包/类
/**
* <p>Gets the time zone display name, using a cache for performance.</p>
*
* @param tz the zone to query
* @param daylight true if daylight savings
* @param style the style to use <code>TimeZone.LONG</code>
* or <code>TimeZone.SHORT</code>
* @param locale the locale to use
* @return the textual name of the time zone
*/
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
Object key = new TimeZoneDisplayKey(tz, daylight, style, locale);
String value = (String) cTimeZoneDisplayCache.get(key);
if (value == null) {
// This is a very slow call, so cache the results.
value = tz.getDisplayName(daylight, style, locale);
cTimeZoneDisplayCache.put(key, value);
}
return value;
}
示例11: sign
import java.util.TimeZone; //导入依赖的package包/类
/**
* Query string authentication. Query string authentication is useful for giving HTTP or
* browser access to resources that would normally require authentication. The signature in the query
* string secures the request.
*
* @param seconds Expire in n seconds from now in default timezone
* @return A signed URL with a limited validity over time.
*/
protected DescriptiveUrl sign(final Path file, final int seconds) {
// Determine expiry time for URL
final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
expiry.add(Calendar.SECOND, seconds);
final String secret = store.findLoginPassword(session.getHost());
if(StringUtils.isBlank(secret)) {
log.warn("No secret found in keychain required to sign temporary URL");
return DescriptiveUrl.EMPTY;
}
String region = null;
if(session.isConnected()) {
region = session.getClient().getRegionEndpointCache()
.getRegionForBucketName(containerService.getContainer(file).getName());
}
return new DescriptiveUrl(URI.create(new S3PresignedUrlProvider().create(
session.getHost(),
session.getHost().getCredentials().getUsername(), secret,
containerService.getContainer(file).getName(), region, containerService.getKey(file),
expiry.getTimeInMillis())), DescriptiveUrl.Type.signed,
MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3"))
+ " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")",
UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis()))
);
}
示例12: parseDate
import java.util.TimeZone; //导入依赖的package包/类
public static Date parseDate(String timestampStr, List<String> dateFormats, String timezone)
throws ParseException {
Date date = null;
SimpleDateFormat sdf = new SimpleDateFormat();
for (String s : dateFormats) {
sdf.applyPattern(s);
if (timezone != null && !timezone.isEmpty()) {
sdf.setTimeZone(TimeZone.getTimeZone(timezone));
}
try {
date = sdf.parse(timestampStr);
} catch (ParseException ignored) {
//do nothing
}
}
if (date == null) {
throw new ParseException(timestampStr, 0);
}
return date;
}
示例13: getStartAndEndDateForWeek
import java.util.TimeZone; //导入依赖的package包/类
protected static Map<String, Object> getStartAndEndDateForWeek(String period) {
Map<String, Object> dateMap = new HashMap<>();
Map<String, Integer> periodMap = getDaysByPeriodStr(period);
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
int firstDayOfWeek = calendar.getFirstDayOfWeek();
calendar.add(Calendar.DATE, -(calendar.get(Calendar.DAY_OF_WEEK)-firstDayOfWeek));
calendar.add(Calendar.WEEK_OF_YEAR, 1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
String endDateStr = sdf.format(calendar.getTime());
dateMap.put(endDate, endDateStr);
dateMap.put(endTimeMilis, calendar.getTimeInMillis());
calendar.add(periodMap.get(KEY), -(periodMap.get(VALUE)));
calendar.add(Calendar.DATE, 1);
calendar.set(Calendar.HOUR_OF_DAY,0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
dateMap.put(INTERVAL, "1w");
dateMap.put(FORMAT, "yyyy-ww");
String startDateStr = sdf.format(calendar.getTime());
dateMap.put(startDate, startDateStr);
dateMap.put(startTimeMilis, calendar.getTimeInMillis());
return dateMap;
}
示例14: getCredentialString
import java.util.TimeZone; //导入依赖的package包/类
@Test
public void getCredentialString() {
ClientConfig config = new ClientConfig.Builder().accessKey("TESTESTSERSERESTSET").secretKey("KJSAKDFJASKFDJASDFJSAFDJSJFSAJFSDF").build();
Auth auth = new Auth(config);
String body = "";
SimpleDateFormat ISO8601DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
ISO8601DATEFORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
String date_s = "2017-10-28T19:57:56";
Date date = new Date();
try {
date = ISO8601DATEFORMAT.parse(date_s);
} catch (ParseException e) {
e.printStackTrace();
}
String a = auth.getCredentialString("POST", "/v2/kernel/create", date, body);
assertEquals(a, "TESTESTSERSERESTSET:dcd926f4b281e05d384b3debccd540b1cd9ad30c184f5797057616f3b86b2cc3");
}
示例15: toLocal
import java.util.TimeZone; //导入依赖的package包/类
public static String toLocal(String utc) {
String pattern = "yyyyMMddHHmmss";
try {
SimpleDateFormat formater = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault());
formater.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = formater.parse(utc);
formater.setTimeZone(TimeZone.getDefault());
return formater.format(date);
} catch (Exception e) {
LOG.i(TAG, "[utc:" + utc + "] UTC to local failed(Exception)", e);
return "";
}
}