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 testAsUtcDayDate() {
    Calendar localTime = Calendar.getInstance(TimeZone.getTimeZone("CST"));
    Calendar cal = DateHelper.asUtcDay(localTime.getTime());
    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:Main.java

static int XmlDateDecoder(String dateStr) {
    if (dateStr == null) {
        return 0;
    }/*  w w  w  .  j  a  va 2  s. co  m*/

    try {
        FORMATTER_XML.setTimeZone(TimeZone.getTimeZone("GMT"));
        return (int) (FORMATTER_XML.parse(dateStr).getTime() / 1000);
    } catch (ParseException e) {
        //throw new RuntimeException(e);
        return 0;
    }
}

From source file:Main.java

static int WbXmlDateDecoder(String dateStr) {
    if (dateStr == null) {
        return 0;
    }//from   w  w w.ja  va 2s  .c o  m
    try {
        FORMATTER_WBXML.setTimeZone(TimeZone.getTimeZone("GMT"));
        if (dateStr.length() < 14) {
            //pading '0'
            String res = String.format("%-14s", dateStr).replace(' ', '0');
            return (int) (FORMATTER_WBXML.parse(res).getTime() / 1000);
        } else {
            return (int) (FORMATTER_WBXML.parse(dateStr).getTime() / 1000);
        }
    } catch (ParseException e) {
        //throw new RuntimeException(e);
        return 0;
    }
}

From source file:de.hanbei.httpserver.response.ResponseBuilder.java

ResponseBuilder(Response response) {
    this.response = response;
    dateFormat = new SimpleDateFormat("EEE, dd MMM yyyyy HH:mm:ss z");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
}

From source file:com.intuit.tank.harness.functions.JexlDateFunctions.java

/**
 * Get the current date.//w  w  w.j  a  v  a 2  s .c  om
 * 
 * @param format
 *            The format of the response (MM-dd-yyyy, MMddyyyy, etc)
 * @param timezone
 *            the timeZone that the date should be formatted in.
 * 
 * @return The current date
 */
public String currentDate(String format, String timezone) {
    DateFormat formatter = getFormatter(format);
    if (StringUtils.isNotBlank(timezone)) {
        formatter.setTimeZone(TimeZone.getTimeZone(timezone));
    }
    return formatter.format(new Date());
}

From source file:com.lfv.yada.net.server.ServerLogger.java

public ServerLogger(int groupId, String logpath) {
    // Create a logger for this class
    if (logpath == null) {
        logpath = "data/logs/";
    }/*  ww  w. ja  v  a 2 s . co  m*/
    mylogpath = logpath;
    log = LogFactory.getLog(getClass());
    log.info("ServerLogger: logpath=" + logpath);

    // Create a calendar
    startTime = System.currentTimeMillis();
    calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.setTimeInMillis(startTime);
    String filename = "Grp" + groupId + "-" + calendar.get(Calendar.YEAR) + s2(calendar.get(Calendar.MONTH) + 1)
            + s2(calendar.get(Calendar.DAY_OF_MONTH)) + "-" + s2(calendar.get(Calendar.HOUR_OF_DAY))
            + s2(calendar.get(Calendar.MINUTE)) + s2(calendar.get(Calendar.SECOND)) + ".log";
    try {
        printer = new PrintStream(new FileOutputStream(logpath + "/" + filename), true);

        log.info("Creating log " + logpath + "/" + filename);
    } catch (FileNotFoundException ex) {
        log.warn("Log file " + filename + " could not be created, logger has been disabled!", ex);
        printer = null;
    }
}

From source file:com.appglu.impl.AbstractAppGluApiTest.java

@Before
public void setup() {
    /* Setting time zone to GMT+0 avoiding time zone issues in tests */
    TimeZone gmt = TimeZone.getTimeZone("GMT");
    TimeZone.setDefault(gmt);//from   w  w  w  .j a  va2 s . com

    appGluTemplate = createAppGluTemplate();

    mockServer = MockRestServiceServer.createServer(appGluTemplate.getRestTemplate());

    responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(jsonMediaType);
}

From source file:com.pinterest.secor.parser.TimestampedMessageParser.java

public TimestampedMessageParser(SecorConfig config) {
    super(config);

    String partitionDateFormat = config.getPartitionDateFormat();
    if (StringUtils.isNotBlank(partitionDateFormat)) {
        mPartitionFormat = new SimpleDateFormat(partitionDateFormat);
    } else {/*  w  w  w .  ja va  2s .c o  m*/
        mPartitionFormat = new SimpleDateFormat("yyyy-MM-dd");
    }
    mPartitionFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    String partitionPrefix = config.getPartitionPrefix();
    if (partitionPrefix != null) {
        mPartitionPrefix = partitionPrefix;
    } else {
        mPartitionPrefix = "dt=";
    }
}

From source file:net.solarnetwork.util.JodaDateTimeSerializer.java

/**
 * Default constructor.//from w w  w  .  j  a  v  a  2s .c  om
 * 
 * <p>
 * Uses the pattern <code>yyyy-MM-dd HH:mm:ss.SSS'Z'</code>.
 * </p>
 */
public JodaDateTimeSerializer() {
    this("yyyy-MM-dd HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("GMT"));
}

From source file:com.sugaronrest.restapicalls.responses.BaseResponse.java

/**
 * Initializes a new instance of the BaseResponse class
 *///from www .  j a  v a 2  s .  c o m
public BaseResponse() {

    final SimpleDateFormat format = new SimpleDateFormat(DATEFORMAT);
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date currenTime = Calendar.getInstance().getTime();
    time = format.format(currenTime) + " UTC";
    this.setError(new ErrorResponse());
    this.statusCode = HttpStatus.SC_OK;
}