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


Java TimeZone.setDefault方法代码示例

本文整理汇总了Java中java.util.TimeZone.setDefault方法的典型用法代码示例。如果您正苦于以下问题:Java TimeZone.setDefault方法的具体用法?Java TimeZone.setDefault怎么用?Java TimeZone.setDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.TimeZone的用法示例。


在下文中一共展示了TimeZone.setDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.util.TimeZone; //导入方法依赖的package包/类
public static void main(String[] args) {
    boolean pass = true;

    TimeZone tz = TimeZone.getDefault();
    try {
        pass &= testRequiredLocales();
        pass &= testRequiredEncodings();
    } finally {
        TimeZone.setDefault(tz);
    }

    if (!pass) {
        System.out.println("\nSome tests failed.\n"
                + "If you installed the US-only J2RE for Windows, "
                + "failures are expected and OK.\n"
                + "If you installed the international J2RE, or any J2SDK, "
                + "or if this occurs on any platform other than Windows, "
                + "please file a bug report.\n"
                + "Unfortunately, this test cannot determine whether you "
                + "installed a US-only J2RE, an international J2RE, or "
                + "a J2SDK.\n");
        throw new RuntimeException();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:InternationalBAT.java

示例2: onSetUpInTransaction

import java.util.TimeZone; //导入方法依赖的package包/类
@Override
protected void onSetUpInTransaction() throws Exception
{
    nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
    importerService = (ImporterService)applicationContext.getBean(ServiceRegistry.IMPORTER_SERVICE.getLocalName());
    
    importerBootstrap = (ImporterBootstrap)applicationContext.getBean("spacesBootstrap");
    
    this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    this.versionService = (VersionService)this.applicationContext.getBean("VersionService");
    
    // Create the store
    this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    
    TimeZone tz = TimeZone.getTimeZone("GMT");
    TimeZone.setDefault(tz);
    // Joda time has already grabbed the JVM zone so re-set it here
    DateTimeZone.setDefault(DateTimeZone.forTimeZone(tz));
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:ImporterComponentTest.java

示例3: testDateParser

import java.util.TimeZone; //导入方法依赖的package包/类
public void testDateParser()
{
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

    String test = "2005-09-16T17:01:03.456+01:00";
    String test2 = "1801-09-16T17:01:03.456+01:00";

    String isoFormattedDate = "2005-09-16T16:01:03.456Z";
    String isoFormattedDate2 = "1801-09-16T16:01:03.456Z";

    Date testDate = getDateValue(2005, 9, 16, 17, 1, 3, 456, 60);
    Date testDate2 = getDateValue(1801, 9, 16, 17, 1, 3, 456, 60);

    // convert to a date
    Date date = ISO8601DateFormat.parse(test);
    Date date2 = ISO8601DateFormat.parse(test2);
    // check converted to date value
    assertEquals(testDate, date);
    assertEquals(testDate2, date2);

    // get the string form
    String strDate = ISO8601DateFormat.format(date);
    String strDate2 = ISO8601DateFormat.format(date2);
    // check the date converted to sting
    assertEquals(isoFormattedDate, strDate);
    assertEquals(isoFormattedDate2, strDate2);
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:28,代码来源:ISO8601DateFormatTest.java

示例4: testGetCalendarMethod

import java.util.TimeZone; //导入方法依赖的package包/类
public void testGetCalendarMethod()
{
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    Calendar calendarGMT = ISO8601DateFormat.getCalendar();

    TimeZone.setDefault(TimeZone.getTimeZone("BST"));
    Calendar calendarBST = ISO8601DateFormat.getCalendar();

    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    Calendar calendarGMT1 = ISO8601DateFormat.getCalendar();

    assertNotSame(calendarGMT, calendarBST);
    assertSame(calendarGMT, calendarGMT1);
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:15,代码来源:ISO8601DateFormatTest.java

示例5: setUp

import java.util.TimeZone; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    context = RuntimeEnvironment.application;

    TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo"));
    BinaryTempFileBody.setTempDirectory(context.getCacheDir());
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:8,代码来源:MessageTest.java

示例6: getEndOfWeek_endInNextMonth

import java.util.TimeZone; //导入方法依赖的package包/类
@Test
public void getEndOfWeek_endInNextMonth() {
    // given
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

    // when (Mon, 26 Nov 2012 00:00:00 GMT)
    Calendar endOfWeek = DateConverter.getEndOfWeek(1353888000000L);

    // then
    assertEquals(1354492799999L, endOfWeek.getTimeInMillis());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:DateConverterTest.java

示例7: getEndOfWeek

import java.util.TimeZone; //导入方法依赖的package包/类
@Test
public void getEndOfWeek() {
    // given
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

    // when (Fri, 14 Dec 2012 13:38:45 GMT)
    Calendar endOfWeek = DateConverter.getEndOfWeek(1355492325000L);

    // then
    assertEquals(1355702399999L, endOfWeek.getTimeInMillis());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:DateConverterTest.java

示例8: main

import java.util.TimeZone; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    Locale reservedLocale = Locale.getDefault();
    TimeZone reservedTimeZone = TimeZone.getDefault();
    try {
        TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
        Locale.setDefault(Locale.US);

        new FieldStateTest().run(args);
    } finally {
        // restore the reserved locale and time zone
        Locale.setDefault(reservedLocale);
        TimeZone.setDefault(reservedTimeZone);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:FieldStateTest.java

示例9: getStartOfNextWeek_EndOfWeek

import java.util.TimeZone; //导入方法依赖的package包/类
@Test
public void getStartOfNextWeek_EndOfWeek() {
    // given
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

    // when (Son, 6 Jan 2013 23:59:59 GMT)
    Calendar startOfNextWeek = DateConverter
            .getStartOfNextWeek(1357516799000L);

    // then (Mon, 7 Jan 2013 0:0:0 GMT)
    assertEquals(1357516800000L, startOfNextWeek.getTimeInMillis());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:13,代码来源:DateConverterTest.java

示例10: getStartOfNextHour

import java.util.TimeZone; //导入方法依赖的package包/类
@Test
public void getStartOfNextHour() {
    // given
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

    // when (Fri, 14 Dec 2012 13:16:05 GMT)
    Calendar startOfHour = DateConverter.getStartOfNextHour(1355490965000L);

    // then
    assertEquals(1355493600000L, startOfHour.getTimeInMillis());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:DateConverterTest.java

示例11: getStartOfHour

import java.util.TimeZone; //导入方法依赖的package包/类
@Test
public void getStartOfHour() {
    // given
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

    // when (Fri, 14 Dec 2012 13:16:05 GMT)
    Calendar startOfHour = DateConverter.getStartOfHour(1355490965000L);

    // then
    assertEquals(1355490000000L, startOfHour.getTimeInMillis());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:DateConverterTest.java

示例12: test

import java.util.TimeZone; //导入方法依赖的package包/类
private static int test(String timeZoneID) throws Throwable {
    File f = new File("test-timezone.txt");
    int failures = 0;
    try {
        f.createNewFile();

        if (timeZoneID != null) {
            TimeZone.setDefault(TimeZone.getTimeZone(timeZoneID));
        }

        boolean succeeded = f.setLastModified(TIME);
        if (!succeeded) {
            System.err.format
                ("Setting time to %d failed for time zone %s%n",
                TIME, timeZoneID);
            failures++;
        }

        long time = f.lastModified();
        if (Math.abs(time - TIME) > 999) { // account for second precision
            System.err.format
                ("Wrong modification time (ms): expected %d, obtained %d%n",
                TIME, time);
            failures++;
        }
    } finally {
        f.delete();
    }

    return failures;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:TimeZoneLastModified.java

示例13: firstShouldGetPreference

import java.util.TimeZone; //导入方法依赖的package包/类
@Test public void firstShouldGetPreference() {
  assertThat(TimeZone.getDefault()).isEqualTo(TIME_ZONE_GMT_8);

  TimeZone.setDefault(TIME_ZONE_GMT_5); // Mutate the actual Time zone.
}
 
开发者ID:vanniktech,项目名称:junit-rules,代码行数:6,代码来源:DefaultTimeZoneRuleWithPreferenceTest.java

示例14: testTextPlusRfc822Message

import java.util.TimeZone; //导入方法依赖的package包/类
@Test
public void testTextPlusRfc822Message() throws MessagingException {
    K9ActivityCommon.setLanguage(context, "en");
    Locale.setDefault(Locale.US);
    TimeZone.setDefault(TimeZone.getTimeZone("GMT+01:00"));

    String innerBodyText = "Hey there. I'm inside a message/rfc822 (inline) attachment.";

    // Create text/plain body
    TextBody textBody = new TextBody(BODY_TEXT);

    // Create inner text/plain body
    TextBody innerBody = new TextBody(innerBodyText);

    // Create message/rfc822 body
    MimeMessage innerMessage = new MimeMessage();
    innerMessage.addSentDate(new Date(112, 2, 17), false);
    innerMessage.setRecipients(RecipientType.TO, new Address[] { new Address("[email protected]") });
    innerMessage.setSubject("Subject");
    innerMessage.setFrom(new Address("[email protected]"));
    MimeMessageHelper.setBody(innerMessage, innerBody);

    // Create multipart/mixed part
    MimeMultipart multipart = MimeMultipart.newInstance();
    MimeBodyPart bodyPart1 = new MimeBodyPart(textBody, "text/plain");
    MimeBodyPart bodyPart2 = new MimeBodyPart(innerMessage, "message/rfc822");
    bodyPart2.setHeader("Content-Disposition", "inline; filename=\"message.eml\"");
    multipart.addBodyPart(bodyPart1);
    multipart.addBodyPart(bodyPart2);

    // Create message
    MimeMessage message = new MimeMessage();
    MimeMessageHelper.setBody(message, multipart);

    // Extract text
    List<Part> outputNonViewableParts = new ArrayList<Part>();
    ArrayList<Viewable> outputViewableParts = new ArrayList<>();
    MessageExtractor.findViewablesAndAttachments(message, outputViewableParts, outputNonViewableParts, null);
    ViewableExtractedText container = messageViewInfoExtractor.extractTextFromViewables(outputViewableParts);

    String expectedText =
            BODY_TEXT +
            "\r\n\r\n" +
            "----- message.eml ------------------------------------------------------" +
            "\r\n\r\n" +
            "From: [email protected]" + "\r\n" +
            "To: [email protected]" + "\r\n" +
            "Sent: Sat Mar 17 00:00:00 GMT+01:00 2012" + "\r\n" +
            "Subject: Subject" + "\r\n" +
            "\r\n" +
            innerBodyText;
    String expectedHtml =
            "<pre class=\"k9mail\">" +
                    BODY_TEXT_HTML +
            "</pre>" +
            "<p style=\"margin-top: 2.5em; margin-bottom: 1em; border-bottom: " +
                    "1px solid #000\">message.eml</p>" +
            "<table style=\"border: 0\">" +
            "<tr>" +
            "<th style=\"text-align: left; vertical-align: top;\">From:</th>" +
            "<td>[email protected]</td>" +
            "</tr><tr>" +
            "<th style=\"text-align: left; vertical-align: top;\">To:</th>" +
            "<td>[email protected]</td>" +
            "</tr><tr>" +
            "<th style=\"text-align: left; vertical-align: top;\">Sent:</th>" +
            "<td>Sat Mar 17 00:00:00 GMT+01:00 2012</td>" +
            "</tr><tr>" +
            "<th style=\"text-align: left; vertical-align: top;\">Subject:</th>" +
            "<td>Subject</td>" +
            "</tr>" +
            "</table>" +
            "<pre class=\"k9mail\">" +
            innerBodyText +
            "</pre>";

    assertEquals(expectedText, container.text);
    assertEquals(expectedHtml, container.html);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:80,代码来源:MessageViewInfoExtractorTest.java

示例15: main

import java.util.TimeZone; //导入方法依赖的package包/类
public static void main(String[] args) {
    TimeZone UTC = TimeZone.getTimeZone("UTC");
    TimeZone initTz = TimeZone.getDefault();

    List<String> errors = new ArrayList<>();
    try {
        TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
        for (Locale locale : DateFormat.getAvailableLocales()) {
            // exclude any locales which localize "UTC".
            String utc = UTC.getDisplayName(false, SHORT, locale);
            if (!"UTC".equals(utc)) {
                System.out.println("Skipping " + locale + " due to localized UTC name: " + utc);
                continue;
            }
            SimpleDateFormat fmt = new SimpleDateFormat("z", locale);
            try {
                Date date = fmt.parse("UTC");
                // Parsed one may not exactly be UTC. Universal, UCT, etc. are equivalents.
                if (!fmt.getTimeZone().getID().matches("(Etc/)?(UTC|Universal|UCT|Zulu)")) {
                    errors.add("timezone: " + fmt.getTimeZone().getID()
                               + ", locale: " + locale);
                }
            } catch (ParseException e) {
                errors.add("parse exception: " + e + ", locale: " + locale);
            }
        }
    } finally {
        // Restore the default time zone
        TimeZone.setDefault(initTz);
    }

    if (!errors.isEmpty()) {
        System.out.println("Got unexpected results:");
        for (String s : errors) {
            System.out.println("    " + s);
        }
        throw new RuntimeException("Test failed.");
    } else {
        System.out.println("Test passed.");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:42,代码来源:Bug8141243.java


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