当前位置: 首页>>代码示例>>Java>>正文


Java Calendar.setTimeZone方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:TestJapaneseChronoImpl.java

示例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());
    }

}
 
开发者ID:SpeedPromise,项目名称:L-Assistant,代码行数:17,代码来源:ZhihuDailyFragment.java

示例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;
}
 
开发者ID:a-hansen,项目名称:alog,代码行数:23,代码来源:Time.java

示例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"));
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:19,代码来源:Aws4SignerTest.java

示例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");
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:23,代码来源:Aws4SignerTest.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:45,代码来源:CronSequenceGenerator.java

示例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"));
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:19,代码来源:AWS4SignerTest.java

示例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);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:23,代码来源:Aws4SignerTest.java

示例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;
}
 
开发者ID:lemon-china,项目名称:lemon-framework,代码行数:10,代码来源:DateUtil.java

示例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;
}
 
开发者ID:aschattney,项目名称:dagger-test-example,代码行数:12,代码来源:DateProvider.java

示例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;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:50,代码来源:SMSBuilder.java

示例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));
}
 
开发者ID:ARMmbed,项目名称:mbed-cloud-sdk-java,代码行数:11,代码来源:TestTranslationUtils.java

示例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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:CalendarRegression.java

示例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));
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:35,代码来源:EfdcRestartFileTest.java

示例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;
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:36,代码来源:DatePropertyTagRule.java


注:本文中的java.util.Calendar.setTimeZone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。