Example usage for java.util TimeZone getTimeZone

List of usage examples for java.util TimeZone getTimeZone

Introduction

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

Prototype

public static TimeZone getTimeZone(ZoneId zoneId) 

Source Link

Document

Gets the TimeZone for the given zoneId .

Usage

From source file:helper.lang.DateHelperTest.java

@Test
public void testAsUtcDayCalendar() {
    Calendar localTime = Calendar.getInstance(TimeZone.getTimeZone("CST"));
    Calendar cal = DateHelper.asUtcDay(localTime);
    assertEquals(0, cal.get(Calendar.MILLISECOND));
    assertEquals(0, cal.get(Calendar.MINUTE));
    assertEquals(0, cal.get(Calendar.HOUR));
    assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(DateHelper.UTC_TIME_ZONE, cal.getTimeZone());
    assertEquals(TimeZone.getTimeZone("CST"), localTime.getTimeZone());
    assertEquals(localTime.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(localTime.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(localTime.get(Calendar.DATE), cal.get(Calendar.DATE));
}

From source file:jp.classmethod.aws.brian.job.BrianQuartzJobBean.java

static SimpleDateFormat createFormat() {
    SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Japan")); // TODO localize
    calendar.setMinimalDaysInFirstWeek(4);
    calendar.setFirstDayOfWeek(Calendar.MONDAY);
    calendar.setTimeInMillis(0);/*from w  w w.j  a va2  s.com*/
    format.setCalendar(calendar);
    return format;
}

From source file:com.tdclighthouse.prototype.utils.TdcUtils.java

public static String dateToRFC1123(Date date) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, new Locale("en"));
    dateFormat.setTimeZone(TimeZone.getTimeZone(GMT));
    String result = dateFormat.format(date);
    return result;
}

From source file:com.predic8.membrane.core.util.HttpUtil.java

public static DateFormat createGMTDateFormat() {
    SimpleDateFormat GMT_DATE_FORMAT = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
    GMT_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
    return GMT_DATE_FORMAT;
}

From source file:org.springframework.cloud.stream.metrics.config.MetricJsonSerializer.java

private static DateFormat defaultDateFormat() {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    return df;//from ww  w .  ja v a  2s . c  o  m
}

From source file:com.todopl.foreign.msexchange.MSExchange.java

public static ExchangeService getVersionedService(ExchangeVersion version, String username, String passwd,
        String email) throws Exception {

    ExchangeService service = new ExchangeService(version, TimeZone.getTimeZone("UTC"));
    ExchangeCredentials creds = new WebCredentials(username, passwd);
    service.setCredentials(creds);/*from www .  j  a va  2  s  .c om*/
    service.autodiscoverUrl(email);

    return service;
}

From source file:GmtDate.java

/**
 *  Description of the Method/*from  w w  w.  j ava  2s .c o  m*/
 *
 * @param  date  Description of the Parameter
 * @return       Description of the Return Value
 */
public final static String format(Date date) {
    formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    fullString = formatter.format(date);
    return fullString.substring(0, 32);
}

From source file:Main.java

public static String xmlSerialize(Date date) {
    if (date == null) {
        return null;
    }//from  w  w  w  .  j a  v  a 2  s .com
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.'SSSZ");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    return sdf.format((Date) date);
}

From source file:Main.java

public static final Date stringToDate(String paramString1, String paramString2, boolean paramBoolean) {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat(paramString2, Locale.getDefault());
    localSimpleDateFormat.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
    try {/*w  w w  .j  av a 2  s.  c om*/
        Date localDate = localSimpleDateFormat.parse(paramString1);
        return localDate;
    } catch (Throwable localThrowable) {
        if (!paramBoolean) {
            return new Date(1000L + System.currentTimeMillis());
        }
    }
    return null;
}

From source file:com.collabnet.ccf.core.utils.DateUtil.java

/**
 * Converts the given Date object into another date object with the
 * specified time zone information.//w w w  . j  a  v a2  s.com
 * 
 * @param date
 *            - The date that is to be converted to a different time zone.
 * @param toTimeZone
 *            - the time zone to which the date object should be converted.
 * @return the new Date object in the specified time zone.
 * @throws ParseException
 */
public static Date convertDate(Date date, String toTimeZone) throws ParseException {
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(toTimeZone));
    cal.setTime(date);
    DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss.SSS Z");
    df.setCalendar(cal);
    return df.parse(df.format(cal.getTime()));
}