Example usage for java.util TimeZone getDefault

List of usage examples for java.util TimeZone getDefault

Introduction

In this page you can find the example usage for java.util TimeZone getDefault.

Prototype

public static TimeZone getDefault() 

Source Link

Document

Gets the default TimeZone of the Java virtual machine.

Usage

From source file:com.nginious.http.serialize.JsonSerializerTestCase.java

public void testJsonSerializer() throws Exception {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");
    SerializableBean bean = new SerializableBean();
    bean.setBooleanValue(true);/*from   w w  w .  jav a 2  s.c om*/
    bean.setDoubleValue(0.451);
    bean.setFloatValue(1.34f);
    bean.setIntValue(3400100);
    bean.setLongValue(3400100200L);
    bean.setShortValue((short) 32767);
    bean.setStringValue("String");
    bean.setDateValue(format.parse("2011-08-24T08:50:23+0200"));
    Date calDate = format.parse("2011-08-24T08:52:23+0200");
    Calendar cal = Calendar.getInstance();
    cal.setTime(calDate);
    bean.setCalendarValue(cal);
    bean.setObjectValue(TimeZone.getDefault());

    InBean inBean = new InBean();
    inBean.setFirst(true);
    inBean.setSecond(0.567d);
    inBean.setThird(0.342f);
    inBean.setFourth(100);
    inBean.setFifth(3400200100L);
    inBean.setSixth((short) 32767);
    inBean.setSeventh("String");
    inBean.setEight(format.parse("2011-08-25T08:50:23+0200"));
    cal = Calendar.getInstance();
    calDate = format.parse("2011-08-25T08:52:23+0200");
    cal.setTime(calDate);
    inBean.setNinth(cal);
    bean.setBeanValue(inBean);

    List<InBean> beanList = new ArrayList<InBean>();
    beanList.add(inBean);
    beanList.add(inBean);
    bean.setBeanListValue(beanList);

    List<String> stringList = new ArrayList<String>();
    stringList.add("One");
    stringList.add("Two");
    stringList.add("Three");
    bean.setStringListValue(stringList);

    ApplicationClassLoader classLoader = new ApplicationClassLoader(
            Thread.currentThread().getContextClassLoader());
    SerializerFactoryImpl serializerFactory = new SerializerFactoryImpl(classLoader);
    Serializer<SerializableBean> serializer = serializerFactory.createSerializer(SerializableBean.class,
            "application/json");
    assertEquals("application/json", serializer.getMimeType());

    StringWriter strWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(strWriter);

    serializer.serialize(writer, bean);
    writer.flush();
    JSONObject json = new JSONObject(strWriter.toString());
    assertNotNull(json);
    assertTrue(json.has("serializableBean"));
    json = json.getJSONObject("serializableBean");

    assertEquals(true, json.getBoolean("booleanValue"));
    assertEquals(0.451, json.getDouble("doubleValue"));
    assertEquals(1.34f, (float) json.getDouble("floatValue"));
    assertEquals(3400100, json.getInt("intValue"));
    assertEquals(3400100200L, json.getLong("longValue"));
    assertEquals(32767, (short) json.getInt("shortValue"));
    assertEquals("String", json.getString("stringValue"));
    assertEquals("2011-08-24T08:50:23+02:00", json.getString("dateValue"));
    assertEquals("2011-08-24T08:52:23+02:00", json.getString("calendarValue"));
    assertEquals(TimeZone.getDefault().toString(), json.getString("objectValue"));

    assertTrue(json.has("beanValue"));
    JSONObject inBeanJson = json.getJSONObject("beanValue");
    assertTrue(inBeanJson.has("inBean"));
    inBeanJson = inBeanJson.getJSONObject("inBean");
    assertEquals(true, inBeanJson.getBoolean("first"));
    assertEquals(0.567, inBeanJson.getDouble("second"));
    assertEquals(0.342f, (float) inBeanJson.getDouble("third"));
    assertEquals(100, inBeanJson.getInt("fourth"));
    assertEquals(3400200100L, inBeanJson.getLong("fifth"));
    assertEquals(32767, (short) inBeanJson.getInt("sixth"));
    assertEquals("String", inBeanJson.getString("seventh"));
    assertEquals("2011-08-25T08:50:23+02:00", inBeanJson.getString("eight"));
    assertEquals("2011-08-25T08:52:23+02:00", inBeanJson.getString("ninth"));

    assertTrue(json.has("stringListValue"));
    JSONArray stringListJson = json.getJSONArray("stringListValue");
    assertEquals("One", stringListJson.get(0));
    assertEquals("Two", stringListJson.get(1));
    assertEquals("Three", stringListJson.get(2));

    assertTrue(json.has("beanListValue"));
    JSONArray beanListJson = json.getJSONArray("beanListValue");

    inBeanJson = beanListJson.getJSONObject(0);
    assertTrue(inBeanJson.has("inBean"));
    inBeanJson = inBeanJson.getJSONObject("inBean");
    assertEquals(true, inBeanJson.getBoolean("first"));
    assertEquals(0.567, inBeanJson.getDouble("second"));
    assertEquals(0.342f, (float) inBeanJson.getDouble("third"));
    assertEquals(100, inBeanJson.getInt("fourth"));
    assertEquals(3400200100L, inBeanJson.getLong("fifth"));
    assertEquals(32767, (short) inBeanJson.getInt("sixth"));
    assertEquals("String", inBeanJson.getString("seventh"));
    assertEquals("2011-08-25T08:50:23+02:00", inBeanJson.getString("eight"));
    assertEquals("2011-08-25T08:52:23+02:00", inBeanJson.getString("ninth"));

    inBeanJson = beanListJson.getJSONObject(1);
    assertTrue(inBeanJson.has("inBean"));
    inBeanJson = inBeanJson.getJSONObject("inBean");
    assertEquals(true, inBeanJson.getBoolean("first"));
    assertEquals(0.567, inBeanJson.getDouble("second"));
    assertEquals(0.342f, (float) inBeanJson.getDouble("third"));
    assertEquals(100, inBeanJson.getInt("fourth"));
    assertEquals(3400200100L, inBeanJson.getLong("fifth"));
    assertEquals(32767, (short) inBeanJson.getInt("sixth"));
    assertEquals("String", inBeanJson.getString("seventh"));
    assertEquals("2011-08-25T08:50:23+02:00", inBeanJson.getString("eight"));
    assertEquals("2011-08-25T08:52:23+02:00", inBeanJson.getString("ninth"));
}

From source file:edu.harvard.iq.safe.lockss.impl.DaemonStatusDataUtil.java

/**
 *
 * @param date/*from  w  w  w.j  a  v  a2  s. c o  m*/
 * @return
 */
public static String getStdFrmtdTime(Date date) {
    return FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss zz", TimeZone.getDefault()).format(date);
}

From source file:com.samples.platform.client.test.ClientTest.java

/** Create the client test. */
public ClientTest() {
    this.applicationContext = new AnnotationConfigApplicationContext(ClientConfig.class);
    this.logger.info("Default timezone is {}", TimeZone.getDefault().getID());
}

From source file:com.orange.clara.pivotaltrackermirror.config.AppConfig.java

@Bean
public Jackson2ObjectMapperBuilder objectMapperBuilder() {
    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    df.setTimeZone(TimeZone.getDefault());
    builder.dateFormat(df);//  ww  w . java 2s.  c om
    return builder;
}

From source file:RolloverFileOutputStream.java

public RolloverFileOutputStream(String filename, boolean append, int retainDays) throws IOException {
    this(filename, append, retainDays, TimeZone.getDefault());
}

From source file:com.ykun.commons.utils.commons.DateUtils.java

/**
 * @param date//from   w w  w  .ja  v  a 2 s  .co  m
 * @return
 * @throws
 * @Description:Date???yyyy-MM-dd HH:mm:ss?
 */
public static String dateToString(Date date) {
    return dateToString(date, YYYY_MM_DD_HH_MM_SS, TimeZone.getDefault());
}

From source file:figs.treeVisualization.gui.PhyloDateAxis.java

/**
 * @param arg0
 */
public PhyloDateAxis(String label) {
    this(label, TimeZone.getDefault());
}

From source file:hudson.plugins.timestamper.TimestampNoteTest.java

/**
 * @throws Exception/* w w w  .  j av  a 2 s.  c o  m*/
 */
@Before
public void setUp() throws Exception {
    systemDefaultTimeZone = TimeZone.getDefault();
    // Set the time zone to get consistent results.
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    setSystemTimeFormat(FORMAT);
}

From source file:DateCache.java

/**
 * Constructor. Make a DateCache that will use a default format. The default
 * format generates the same results as Date.toString().
 *///from w  w  w  . j  a  v a2  s  . co m
public DateCache() {
    this("EEE MMM dd HH:mm:ss zzz yyyy");
    getFormat().setTimeZone(TimeZone.getDefault());
}

From source file:uk.ac.ebi.intact.editor.controller.admin.UserManagerController.java

/**
 *
 * @return the time zone of the application so it does not show one hour of difference when logging
 *///from  w w  w  .  j  a v  a 2  s. co  m
public TimeZone getTimeZone() {
    return TimeZone.getDefault();
}