本文整理匯總了Java中java.util.Calendar.setTimeZone方法的典型用法代碼示例。如果您正苦於以下問題:Java Calendar.setTimeZone方法的具體用法?Java Calendar.setTimeZone怎麽用?Java Calendar.setTimeZone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Calendar
的用法示例。
在下文中一共展示了Calendar.setTimeZone方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_JapaneseChrono_vsCalendar
import java.util.Calendar; //導入方法依賴的package包/類
@Test(dataProvider="RangeVersusCalendar")
public void test_JapaneseChrono_vsCalendar(LocalDate isoStartDate, LocalDate isoEndDate) {
Locale locale = Locale.forLanguageTag("ja-JP-u-ca-japanese");
assertEquals(locale.toString(), "ja_JP_#u-ca-japanese", "Unexpected locale");
Calendar cal = java.util.Calendar.getInstance(locale);
assertEquals(cal.getCalendarType(), "japanese", "Unexpected calendar type");
JapaneseDate jDate = JapaneseChronology.INSTANCE.date(isoStartDate);
// Convert to millis and set Japanese Calendar to that start date (at GMT)
OffsetDateTime jodt = OffsetDateTime.of(isoStartDate, LocalTime.MIN, ZoneOffset.UTC);
long millis = jodt.toInstant().toEpochMilli();
cal.setTimeZone(TimeZone.getTimeZone("GMT+00"));
cal.setTimeInMillis(millis);
while (jDate.isBefore(isoEndDate)) {
assertEquals(jDate.get(ChronoField.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH), "Day mismatch in " + jDate + "; cal: " + cal);
assertEquals(jDate.get(ChronoField.MONTH_OF_YEAR), cal.get(Calendar.MONTH) + 1, "Month mismatch in " + jDate);
assertEquals(jDate.get(ChronoField.YEAR_OF_ERA), cal.get(Calendar.YEAR), "Year mismatch in " + jDate);
jDate = jDate.plus(1, ChronoUnit.DAYS);
cal.add(Calendar.DAY_OF_MONTH, 1);
}
}
示例2: onResume
import java.util.Calendar; //導入方法依賴的package包/類
@Override
public void onResume() {
super.onResume();
mPresenter.start();
Calendar c = Calendar.getInstance();
c.setTimeZone(TimeZone.getTimeZone("GMT+08"));
c.set(mYear, mMonth, mDay);
setLoadingIndicator(mIsFirstLoad);
if (mIsFirstLoad) {
mPresenter.loadNews(true, false, c.getTimeInMillis());
mIsFirstLoad = false;
} else {
mPresenter.loadNews(false, false, c.getTimeInMillis());
}
}
示例3: getCalendar
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Attempts to reuse a calendar instance, the timezone will be set to
* TimeZone.getDefault().
*/
public static Calendar getCalendar() {
Calendar cal = null;
synchronized (Time.class) {
if (calendarCache1 != null) {
cal = calendarCache1;
calendarCache1 = null;
} else if (calendarCache2 != null) {
cal = calendarCache2;
calendarCache2 = null;
}
}
if (cal == null) {
cal = Calendar.getInstance();
} else {
cal.setTimeZone(TimeZone.getDefault());
}
return cal;
}
示例4: testAnonymous
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Tests that if passed anonymous credentials, signer will not generate a signature.
*/
@Test
public void testAnonymous() throws Exception {
AwsCredentials credentials = AnonymousCredentialsProvider.create().getCredentials();
SdkHttpFullRequest request = generateBasicRequest().build();
Calendar c = new GregorianCalendar();
c.set(1981, 1, 16, 6, 30, 0);
c.setTimeZone(TimeZone.getTimeZone("UTC"));
signer.setServiceName("demo");
signer.setOverrideDate(c.getTime());
SignerTestUtils.signRequest(signer, request, credentials);
assertNull(request.headers().get("Authorization"));
}
示例5: xAmznTraceId_NotSigned
import java.util.Calendar; //導入方法依賴的package包/類
/**
* x-amzn-trace-id should not be signed as it may be mutated by proxies or load balancers.
*/
@Test
public void xAmznTraceId_NotSigned() throws Exception {
AwsCredentials credentials = new AwsCredentials("akid", "skid");
SdkHttpFullRequest.Builder request = generateBasicRequest();
request.header("X-Amzn-Trace-Id", " Root=1-584b150a-708479cb060007ffbf3ee1da;Parent=36d3dbcfd150aac9;Sampled=1");
Calendar c = new GregorianCalendar();
c.set(1981, 1, 16, 6, 30, 0);
c.setTimeZone(TimeZone.getTimeZone("UTC"));
signer.setServiceName("demo");
signer.setOverrideDate(c.getTime());
SdkHttpFullRequest actual = SignerTestUtils.signRequest(signer, request.build(), credentials);
assertThat(actual.firstMatchingHeader("Authorization"))
.hasValue("AWS4-HMAC-SHA256 Credential=akid/19810216/us-east-1/demo/aws4_request, " +
"SignedHeaders=host;x-amz-archive-description;x-amz-date, " +
"Signature=581d0042389009a28d461124138f1fe8eeb8daed87611d2a2b47fd3d68d81d73");
}
示例6: next
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Get the next {@link Date} in the sequence matching the Cron pattern and
* after the value provided. The return value will have a whole number of
* seconds, and will be after the input value.
* @param date a seed value
* @return the next value matching the pattern
*/
public Date next(Date date) {
/*
The plan:
1 Round up to the next whole second
2 If seconds match move on, otherwise find the next match:
2.1 If next match is in the next minute then roll forwards
3 If minute matches move on, otherwise find the next match
3.1 If next match is in the next hour then roll forwards
3.2 Reset the seconds and go to 2
4 If hour matches move on, otherwise find the next match
4.1 If next match is in the next day then roll forwards,
4.2 Reset the minutes and seconds and go to 2
...
*/
Calendar calendar = new GregorianCalendar();
calendar.setTimeZone(this.timeZone);
calendar.setTime(date);
// First, just reset the milliseconds and try to calculate from there...
calendar.set(Calendar.MILLISECOND, 0);
long originalTimestamp = calendar.getTimeInMillis();
doNext(calendar, calendar.get(Calendar.YEAR));
if (calendar.getTimeInMillis() == originalTimestamp) {
// We arrived at the original timestamp - round up to the next whole second and try again...
calendar.add(Calendar.SECOND, 1);
doNext(calendar, calendar.get(Calendar.YEAR));
}
return calendar.getTime();
}
示例7: testAnonymous
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Tests that if passed anonymous credentials, signer will not generate a signature
*/
@Test
public void testAnonymous() throws Exception {
AWSCredentials credentials = new AnonymousAWSCredentials();
SignableRequest<?> request = generateBasicRequest();
Calendar c = new GregorianCalendar();
c.set(1981, 1, 16, 6, 30, 0);
c.setTimeZone(TimeZone.getTimeZone("UTC"));
signer.setServiceName("demo");
signer.setOverrideDate(c.getTime());
signer.sign(request, credentials);
assertNull(request.getHeaders().get("Authorization"));
}
示例8: queryParamsWithNullValuesAreStillSignedWithTrailingEquals
import java.util.Calendar; //導入方法依賴的package包/類
@Test
public void queryParamsWithNullValuesAreStillSignedWithTrailingEquals() throws Exception {
final String expectedAuthorizationHeaderWithoutSha256Header =
"AWS4-HMAC-SHA256 Credential=access/19810216/us-east-1/demo/aws4_request, " +
"SignedHeaders=host;x-amz-archive-description;x-amz-date, " +
"Signature=c45a3ff1f028e83017f3812c06b4440f0b3240264258f6e18cd683b816990ba4";
AwsCredentials credentials = new AwsCredentials("access", "secret");
// Test request without 'x-amz-sha256' header
SdkHttpFullRequest.Builder request = generateBasicRequest().rawQueryParameter("Foo", (String) null);
Calendar calendar = new GregorianCalendar();
calendar.set(1981, 1, 16, 6, 30, 0);
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
signer.setOverrideDate(calendar.getTime());
signer.setServiceName("demo");
SdkHttpFullRequest signed = SignerTestUtils.signRequest(signer, request.build(), credentials);
assertThat(signed.firstMatchingHeader("Authorization"))
.hasValue(expectedAuthorizationHeaderWithoutSha256Header);
}
示例9: getTimestamp
import java.util.Calendar; //導入方法依賴的package包/類
/**
* 獲取當前時間戳
*/
public static long getTimestamp() {
TimeZone time = TimeZone.getTimeZone("GMT+8"); //設置為東八區
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(time);
return calendar.getTimeInMillis() / 1000;
}
示例10: parse
import java.util.Calendar; //導入方法依賴的package包/類
public Calendar parse(String strDate) throws ParseException
{
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
Calendar parsedDate = Calendar.getInstance(Locale.GERMANY);
parsedDate.setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
parsedDate.setTime(dateFormat.parse(strDate));
return parsedDate;
}
示例11: setTransactionDetails
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Method to set details to the transaction object
*
* @param mobileTransModel Mobile transaction model
* @param ua User Account
* @param kioskId Kiosk ID
* @param actualTransactionDate Actual Transaction Date
* @param materialId Material ID
* @return ITransaction
* @throws ParseException when unable to parse date
* @throws ServiceException Exception thrown from Service Layer
*/
private ITransaction setTransactionDetails(MobileTransModel mobileTransModel, IUserAccount ua,
Long kioskId, Long actualTransactionDate,
Long materialId) throws
ParseException, ServiceException {
ITransaction transaction = JDOUtils.createInstance(ITransaction.class);
transaction.setKioskId(kioskId);
transaction.setType(mobileTransModel.ty);
transaction.setBatchId(mobileTransModel.bid);
if (transaction.hasBatch()) {
transaction.setOpeningStockByBatch(mobileTransModel.ostk);
} else {
transaction.setOpeningStock(mobileTransModel.ostk);
}
transaction.setQuantity(mobileTransModel.q);
transaction.setSourceUserId(ua.getUserId());
if (actualTransactionDate != null) {
Date d = LocalDateUtil.parseCustom(mobileTransModel.atd, Constants.DATE_FORMAT, null);
transaction.setAtd(d);
}
transaction.setTimestamp(new Date());
Calendar calendar = Calendar.getInstance();
TimeZone timeZone = SMSUtil.getUserTimeZone(ua);
if (timeZone != null) {
calendar.setTimeZone(timeZone);
}
calendar.setTimeInMillis(mobileTransModel.entm);
transaction.setEntryTime(calendar.getTime());
calendar.setTimeInMillis(mobileTransModel.sortEtm);
transaction.setSortEt(calendar.getTime());
if (mobileTransModel.lkid != null) {
transaction.setLinkedKioskId(mobileTransModel.lkid);
}
transaction.setSrc(SourceConstants.SMS);
transaction.setMaterialId(materialId);
return transaction;
}
示例12: testToRFC3339Timestamp
import java.util.Calendar; //導入方法依賴的package包/類
@Test
public void testToRFC3339Timestamp() {
String timestamp = "2017-08-11T17:33:35.000Z";
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("CET"));
calendar.set(2017, 7, 11, 19, 33, 35);
calendar.set(Calendar.MILLISECOND, 0);
Date datetime = calendar.getTime();
assertEquals(timestamp, TranslationUtils.toUtcTimestamp(datetime));
}
示例13: Test4177484
import java.util.Calendar; //導入方法依賴的package包/類
/**
* Calendar does not update field values when setTimeZone is called.
*/
public void Test4177484() {
TimeZone PST = TimeZone.getTimeZone("PST");
TimeZone EST = TimeZone.getTimeZone("EST");
Calendar cal = Calendar.getInstance(PST, Locale.US);
cal.clear();
cal.set(1999, 3, 21, 15, 5, 0); // Arbitrary
int h1 = cal.get(HOUR_OF_DAY);
cal.setTimeZone(EST);
int h2 = cal.get(HOUR_OF_DAY);
if (h1 == h2) {
errln("FAIL: Fields not updated after setTimeZone");
}
// getTime() must NOT change when time zone is changed.
// getTime() returns zone-independent time in ms.
cal.clear();
cal.setTimeZone(PST);
cal.set(HOUR_OF_DAY, 10);
Date pst10 = cal.getTime();
cal.setTimeZone(EST);
Date est10 = cal.getTime();
if (!pst10.equals(est10)) {
errln("FAIL: setTimeZone changed time");
}
}
示例14: testWriteEfdcRestartFile2
import java.util.Calendar; //導入方法依賴的package包/類
public void testWriteEfdcRestartFile2() {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
calendar.set(2009, 4, 23, 9, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
double startDate = Time.milliesToMjd(calendar.getTimeInMillis());
EfdcRestartFileIoObject efdcRestartFileIoObject = new EfdcRestartFileIoObject();
//working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc
String efdcRestartFilename = "efdcRestartFileTest/input/RESTART2.INP";
String startTimeExchangeItemId = "TSTART1";
efdcRestartFileIoObject.initialize(testRunDataDir, efdcRestartFilename,
new String[]{"0", startTimeExchangeItemId});
//Get all exchangeItems items
IPrevExchangeItem[] exchangeItems = efdcRestartFileIoObject.getExchangeItems();
//Loop over all exchangeItems items and request the ID, name and value
for (IPrevExchangeItem exchangeItem : exchangeItems) {
String id = exchangeItem.getId();
if (id.equals(startTimeExchangeItemId)) {
exchangeItem.setValues(startDate);
}
}
//This command actually replaces the startTime in the restart file.
efdcRestartFileIoObject.finish();
//compare actual result file with expected result file.
File actualOutputFile = new File(testRunDataDir, efdcRestartFilename);
//working directory (testRunDataDir) is openda_public/opendaTestRuns/model_efdc/org/openda/model_efdc
File expectedOutputFile = new File(testRunDataDir, "efdcRestartFileTest/expectedResult/RESTART2.INP");
assertTrue(testData.FilesAreIdentical(expectedOutputFile, actualOutputFile, 0));
}
示例15: _coerceToDate
import java.util.Calendar; //導入方法依賴的package包/類
static private Date _coerceToDate(String str, boolean adjustToEnd)
{
if (str == null)
return null;
try
{
Date date = _getDateFormat().parse(str);
// This code is taken from UIXComponentELTag
// We should probably not do the ajustment here,
// but instead be smarter when days are compared.
if (adjustToEnd)
{
Calendar c = Calendar.getInstance();
TimeZone tz = RequestContext.getCurrentInstance().getTimeZone();
if (tz != null)
c.setTimeZone(tz);
c.setTime(date);
// Original value had 00:00:00 for hours,mins, seconds now maximize those
// to get the latest time value for the date supplied.
c.set (Calendar.HOUR_OF_DAY, 23);
c.set (Calendar.MINUTE, 59);
c.set (Calendar.SECOND, 59);
c.set (Calendar.MILLISECOND, 999);
}
return date;
}
catch (ParseException pe)
{
_LOG.info("CANNOT_PARSE_VALUE_INTO_DATE", str);
return null;
}
}