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


Java GregorianCalendar.setTimeZone方法代码示例

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


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

示例1: timestampToJson

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Test
public void timestampToJson() throws IOException {
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MILLISECOND, 2000000000);
    calendar.add(Calendar.MILLISECOND, 2000000000);
    java.util.Date date = calendar.getTime();

    JsonNode converted = parse(converter.fromConnectData(TOPIC, Timestamp.SCHEMA, date));
    validateEnvelope(converted);
    assertEquals(parse("{ \"type\": \"int64\", \"optional\": false, \"name\": \"org.apache.kafka.connect.data.Timestamp\", \"version\": 1 }"),
            converted.get(JsonSchema.ENVELOPE_SCHEMA_FIELD_NAME));
    JsonNode payload = converted.get(JsonSchema.ENVELOPE_PAYLOAD_FIELD_NAME);
    assertTrue(payload.isLong());
    assertEquals(4000000000L, payload.longValue());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:17,代码来源:JsonConverterTest.java

示例2: getDateValue

import java.util.GregorianCalendar; //导入方法依赖的package包/类
private Date getDateValue(int year, int month, int day, int hours, int minutes, int sec, int msec, int offsetInMinutes)
{
    // minute in millis
    int millisInMinute = 1000 * 60;

    GregorianCalendar gc = new GregorianCalendar();

    // set correct offset
    String[] tzArray = TimeZone.getAvailableIDs(millisInMinute * offsetInMinutes);
    if (tzArray.length > 0)
    {
        gc.setTimeZone(TimeZone.getTimeZone(tzArray[0]));
    }

    // set date
    gc.set(GregorianCalendar.YEAR, year);
    gc.set(GregorianCalendar.MONTH, month - 1);
    gc.set(GregorianCalendar.DAY_OF_MONTH, day);
    gc.set(GregorianCalendar.HOUR_OF_DAY, hours);
    gc.set(GregorianCalendar.MINUTE, minutes);
    gc.set(GregorianCalendar.SECOND, sec);
    gc.set(GregorianCalendar.MILLISECOND, msec);

    return gc.getTime();
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:26,代码来源:ISO8601DateFormatTest.java

示例3: testShortishForDatePatern

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public void testShortishForDatePatern()
{
  GregorianCalendar gcal = new GregorianCalendar();
  gcal.set(2999,Calendar.JUNE,4,0,0,0);

  gcal.setTimeZone(DEFAULT_TIME_ZONE);
  // Make use of this date for testing.
  Date date = gcal.getTime();

  DateTimeConverter dtConv   = new DateTimeConverter();
  Mock mock = buildMockUIComponent();
  UIComponent component = (UIComponent) mock.proxy();
  String inputValue          = "6/4/2999";

  dtConv.setDateStyle("shortish");
  dtConv.setLocale(Locale.ENGLISH);

  Date dt = (Date) dtConv.getAsObject(facesContext, component, inputValue);
  assertEquals(true, isEqual(date, dt));

  String exptectedStr = dtConv.getAsString(facesContext, component, dt);
  assertEquals(inputValue, exptectedStr);
  mock.verify();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:TrinidadDateTimeConverterTest.java

示例4: getBeijingNowTimeString

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static String getBeijingNowTimeString(String format) {
    TimeZone timezone = TimeZone.getTimeZone("Asia/Shanghai");

    Date date = new Date(currentTimeMillis());
    SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.getDefault());
    formatter.setTimeZone(timezone);

    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTimeZone(timezone);
    String prefix = gregorianCalendar.get(Calendar.AM_PM) == Calendar.AM ? "上午" : "下午";

    return prefix + formatter.format(date);
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:14,代码来源:TimeUtil.java

示例5: unmarshal

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
    reader.moveDown();
    final long timeInMillis = Long.parseLong(reader.getValue());
    reader.moveUp();
    final String timeZone;
    if (reader.hasMoreChildren()) {
        reader.moveDown();
        timeZone = reader.getValue();
        reader.moveUp();
    } else { // backward compatibility to XStream 1.1.2 and below
        timeZone = TimeZone.getDefault().getID();
    }

    final GregorianCalendar result = new GregorianCalendar();
    result.setTimeZone(TimeZone.getTimeZone(timeZone));
    result.setTimeInMillis(timeInMillis);

    return result;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:GregorianCalendarConverter.java

示例6: Test4145158

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * GregorianCalendar handling of Dates Long.MIN_VALUE and Long.MAX_VALUE is
 * confusing; unless the time zone has a raw offset of zero, one or the
 * other of these will wrap.  We've modified the test given in the bug
 * report to therefore only check the behavior of a calendar with a zero raw
 * offset zone.
 */
public void Test4145158() {
    GregorianCalendar calendar = new GregorianCalendar();

    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));

    calendar.setTime(new Date(Long.MIN_VALUE));
    int year1 = calendar.get(YEAR);
    int era1 = calendar.get(ERA);

    calendar.setTime(new Date(Long.MAX_VALUE));
    int year2 = calendar.get(YEAR);
    int era2 = calendar.get(ERA);

    if (year1 == year2 && era1 == era2) {
        errln("Fail: Long.MIN_VALUE or Long.MAX_VALUE wrapping around");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:CalendarRegression.java

示例7: getLocalDateAndTime

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Converts an SNMP string representation into a {@link Date} object,
 * and applies time zone conversion to provide the time on the local machine, ie PSM server.
 *
 * @param actAlarmDateAndTime MIB-II DateAndTime formatted. May optionally contain
 *                            a timezone offset in 3 extra bytes
 * @param sysInfoTimeZone     Must be supplied if actAlarmDateAndTime is just local time (with no timezone)
 * @param swVersion           Must be supplied if actAlarmDateAndTime is just local time (with no timezone)
 * @return adjusted {@link Date} or a simple conversion if other fields are null.
 */
public static Date getLocalDateAndTime(String actAlarmDateAndTime, String sysInfoTimeZone,
                                       String swVersion) {
    if (StringUtils.isBlank(actAlarmDateAndTime)) {
        return null;
    }

    GregorianCalendar decodedDateAndTimeCal = btiMakeCalendar(OctetString.fromHexString(actAlarmDateAndTime));
    if ((sysInfoTimeZone == null) || (swVersion == null)) {
        return decodedDateAndTimeCal.getTime();
    }

    TimeZone javaTimeZone = getTimeZone();
    decodedDateAndTimeCal.setTimeZone(javaTimeZone);

    GregorianCalendar localTime = new GregorianCalendar();
    localTime.setTimeInMillis(decodedDateAndTimeCal.getTimeInMillis());

    return localTime.getTime();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:30,代码来源:Bti7000SnmpAlarmConsumer.java

示例8: getCurrentTimeString

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static String getCurrentTimeString() {

        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeZone(TimeZone.getTimeZone(DUBLIN_TIME_ZONE));
        SimpleDateFormat sfd = new SimpleDateFormat(MASK, Locale.ENGLISH);

        return sfd.format(gc.getTime());
    }
 
开发者ID:victoraldir,项目名称:BuddyBook,代码行数:9,代码来源:DateUtils.java

示例9: getCurrentTimeStringNoSeparator

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static String getCurrentTimeStringNoSeparator() {

        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeZone(TimeZone.getTimeZone(DUBLIN_TIME_ZONE));
        SimpleDateFormat sfd = new SimpleDateFormat(MASK_NO_SEPARATOR, Locale.ENGLISH);

        return sfd.format(gc.getTime());
    }
 
开发者ID:victoraldir,项目名称:BuddyBook,代码行数:9,代码来源:DateUtils.java

示例10: getXmlDate

import java.util.GregorianCalendar; //导入方法依赖的package包/类
public static XMLGregorianCalendar getXmlDate(Date dateAndTime) {
    ParamUtil.requireNonNull("dateAndTime", dateAndTime);
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTimeZone(UTC);
    cal.setTime(dateAndTime);

    try {
        XMLGregorianCalendar ret = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
        ret.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
        return ret;
    } catch (DatatypeConfigurationException ex) {
        return null;
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:15,代码来源:XmlUtil.java

示例11: Test4145983

import java.util.GregorianCalendar; //导入方法依赖的package包/类
/**
 * Maximum value for YEAR field wrong.
 */
public void Test4145983() {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date[] DATES = {new Date(Long.MAX_VALUE), new Date(Long.MIN_VALUE)};
    for (int i = 0; i < DATES.length; ++i) {
        calendar.setTime(DATES[i]);
        int year = calendar.get(YEAR);
        int maxYear = calendar.getMaximum(YEAR);
        if (year > maxYear) {
            errln("Failed for " + DATES[i].getTime() + " ms: year="
                    + year + ", maxYear=" + maxYear);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:CalendarRegression.java

示例12: dateToConnect

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Test
public void dateToConnect() {
    Schema schema = Date.SCHEMA;
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.DATE, 10000);
    java.util.Date reference = calendar.getTime();
    String msg = "{ \"schema\": { \"type\": \"int32\", \"name\": \"org.apache.kafka.connect.data.Date\", \"version\": 1 }, \"payload\": 10000 }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    java.util.Date converted = (java.util.Date) schemaAndValue.value();
    assertEquals(schema, schemaAndValue.schema());
    assertEquals(reference, converted);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:JsonConverterTest.java

示例13: timeToConnect

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Test
public void timeToConnect() {
    Schema schema = Time.SCHEMA;
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MILLISECOND, 14400000);
    java.util.Date reference = calendar.getTime();
    String msg = "{ \"schema\": { \"type\": \"int32\", \"name\": \"org.apache.kafka.connect.data.Time\", \"version\": 1 }, \"payload\": 14400000 }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    java.util.Date converted = (java.util.Date) schemaAndValue.value();
    assertEquals(schema, schemaAndValue.schema());
    assertEquals(reference, converted);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:14,代码来源:JsonConverterTest.java

示例14: timestampToConnect

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Test
public void timestampToConnect() {
    Schema schema = Timestamp.SCHEMA;
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.MILLISECOND, 2000000000);
    calendar.add(Calendar.MILLISECOND, 2000000000);
    java.util.Date reference = calendar.getTime();
    String msg = "{ \"schema\": { \"type\": \"int64\", \"name\": \"org.apache.kafka.connect.data.Timestamp\", \"version\": 1 }, \"payload\": 4000000000 }";
    SchemaAndValue schemaAndValue = converter.toConnectData(TOPIC, msg.getBytes());
    java.util.Date converted = (java.util.Date) schemaAndValue.value();
    assertEquals(schema, schemaAndValue.schema());
    assertEquals(reference, converted);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:15,代码来源:JsonConverterTest.java

示例15: dateToJson

import java.util.GregorianCalendar; //导入方法依赖的package包/类
@Test
public void dateToJson() throws IOException {
    GregorianCalendar calendar = new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 0);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.add(Calendar.DATE, 10000);
    java.util.Date date = calendar.getTime();

    JsonNode converted = parse(converter.fromConnectData(TOPIC, Date.SCHEMA, date));
    validateEnvelope(converted);
    assertEquals(parse("{ \"type\": \"int32\", \"optional\": false, \"name\": \"org.apache.kafka.connect.data.Date\", \"version\": 1 }"),
            converted.get(JsonSchema.ENVELOPE_SCHEMA_FIELD_NAME));
    JsonNode payload = converted.get(JsonSchema.ENVELOPE_PAYLOAD_FIELD_NAME);
    assertTrue(payload.isInt());
    assertEquals(10000, payload.intValue());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:16,代码来源:JsonConverterTest.java


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