Example usage for java.util TimeZone getAvailableIDs

List of usage examples for java.util TimeZone getAvailableIDs

Introduction

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

Prototype

public static synchronized String[] getAvailableIDs(int rawOffset) 

Source Link

Document

Gets the available IDs according to the given time zone offset in milliseconds.

Usage

From source file:edu.ucsb.nceas.MCTestCase.java

/**
 * Create a unique docid for testing insert and update. Does not
 * include the 'revision' part of the id.
 * /*w ww.j a va  2  s.c o m*/
 * @return a String docid based on the current date and time
 */
protected String generateDocumentId() {
    try {
        Thread.sleep(1010);
    } catch (InterruptedException ie) {
        debug("Could not sleep: " + ie.getMessage());
    }

    StringBuffer docid = new StringBuffer(prefix);
    docid.append(".");

    // Create a calendar to get the date formatted properly
    String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000);
    SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]);
    pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    Calendar calendar = new GregorianCalendar(pdt);
    Date trialTime = new Date();
    calendar.setTime(trialTime);
    docid.append(calendar.get(Calendar.YEAR));
    docid.append(calendar.get(Calendar.DAY_OF_YEAR));
    docid.append(calendar.get(Calendar.HOUR_OF_DAY));
    docid.append(calendar.get(Calendar.MINUTE));
    docid.append(calendar.get(Calendar.SECOND));

    return docid.toString();
}