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:alfio.controller.api.admin.LocationApiController.java

@RequestMapping(value = "/location/map", method = GET)
public String getMapUrl(@RequestParam("lat") String latitude, @RequestParam("long") String longitude) {
    Validate.notBlank(latitude);/*from  ww w. j  av  a2  s  . c  o  m*/
    Validate.notBlank(longitude);
    LocationDescriptor descriptor = LocationDescriptor.fromGeoData(Pair.of(latitude, longitude),
            TimeZone.getDefault(), getMapsClientApiKey());
    return descriptor.getMapUrl();
}

From source file:com.opendesign.utils.Day.java

/**
 * Constructs a specific date//  w w  w .java2s  . co m
 * 
 * @param yyyy
 *            year (full year, e.g., 1996, <i>not</i> starting from 1900)
 * @param m
 *            month
 * @param d
 *            day
 * @exception IllegalArgumentException
 *                if yyyy m d not a valid date
 */
public Day(int yyyy, int m, int d, TimeZone zone) {
    if (zone != null) {
        this.timeZone = zone;
    } else {
        this.timeZone = TimeZone.getDefault();
    }
    this.year = yyyy;
    this.month = m;
    this.day = d;
    if (!isValid()) {
        throw new IllegalArgumentException("Not valid Date(yyyyMMdd) : " + year + ", " + month + ", " + day);
    }
}

From source file:com.todoroo.astrid.actfm.sync.ActFmInvoker.java

/**
 * Authentication user with Act.fm server, returning a token
 *//*w  w w .j a v a2 s. co m*/
public JSONObject authenticate(String email, String firstName, String lastName, String provider, String secret)
        throws ActFmServiceException, IOException {
    JSONObject result = invoke("user_signin", "email", email, "first_name", firstName, "last_name", lastName,
            "provider", provider, "secret", secret, "timezone", TimeZone.getDefault().getID());
    try {
        token = result.getString("token");
    } catch (JSONException e) {
        throw new IOException(e.toString());
    }
    return result;
}

From source file:net.homelinux.penecoptero.android.citybikes.app.AccountHelper.java

private String getUrl(String url) {
    // Check if token is still valid
    if (token == null || expiryDate.before(new Date(System.currentTimeMillis()))) {
        try {/*from w  ww  .j a va2 s .c  om*/
            // Get token
            JSONObject response = new JSONObject(
                    getRESTHelper().restGET(SERVER_URL + "/token/key/b885ab926fdca7dbfbf717084fb36b5f"));
            // Token ID
            token = response.getString("token");
            // Get expiration date given as UTC date and convert it to local time zone
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'");
            expiryDate = sdf.parse(response.getString("endValidity"));
            expiryDate.setTime(expiryDate.getTime() + TimeZone.getDefault().getOffset(expiryDate.getTime()));

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (HttpException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    try {
        return getRESTHelper().restGET(url + (url.indexOf('?') > 0 ? '&' : '?') + "token=" + token);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

From source file:mvm.rya.indexing.accumulo.temporal.TemporalInstantTest.java

@Test
public void constructorTest() throws Exception {
    TemporalInstant instant = new TemporalInstantRfc3339(2014, 12, 30, //
            12, 59, 59);/*from w  ww. ja  v a  2  s . c o m*/
    // YYYY-MM-DDThh:mm:ssZ
    String stringTestDate01 = "2014-12-30T12:59:59Z";
    Date dateTestDate01 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(stringTestDate01);
    Assert.assertEquals(stringTestDate01, instant.getAsKeyString());
    Assert.assertArrayEquals(StringUtils.getBytesUtf8(instant.getAsKeyString()), instant.getAsKeyBytes());
    Assert.assertTrue("Key must be normalized to time zone Zulu", instant.getAsKeyString().endsWith("Z"));
    // show the local time us.
    // Warning, if test is run in the London, or Zulu time zone, this test will be same as above, with the Z.
    // TimeZone.setDefault(TimeZone.getTimeZone("UTC")); // this does not affect the library, don't use.
    String stringLocalTestDate01 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(dateTestDate01);
    // for ET, will be: "2014-12-30T07:59:59-05:00"
    //instant.getAsDateTime().withZone(null);
    //      System.out.println("===System.getProperty(user.timezone)="+System.getProperty("user.timezone")); //=ET
    //      System.out.println("===============TimeZone.getDefault()="+TimeZone.getDefault());            //=ET
    //      System.out.println("===========DateTimeZone.getDefault()="+DateTimeZone.getDefault());         //=UTC (wrong!)
    // the timezone default gets set to UTC by some prior test, fix it here.
    DateTimeZone newTimeZone = null;
    try {
        String id = System.getProperty("user.timezone");
        if (id != null) {
            newTimeZone = DateTimeZone.forID(id);
        }
    } catch (RuntimeException ex) {
        // ignored
    }
    if (newTimeZone == null) {
        newTimeZone = DateTimeZone.forTimeZone(TimeZone.getDefault());
    }
    DateTimeZone.setDefault(newTimeZone);
    // null timezone means use the default:
    Assert.assertEquals("Joda time library (actual) should use same local timezone as Java date (expected).",
            stringLocalTestDate01, instant.getAsReadable(null));
}

From source file:DateCache.java

public DateCache(String format, Locale l) {
    _formatString = format;
    _locale = l;
    setTimeZone(TimeZone.getDefault());
}

From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java

@Override
protected void setUp() {
    super.setUp();
    this.oldTimeZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
    Locale.setDefault(Locale.US);
    gson = new Gson();
}

From source file:di.uniba.it.tee2.extraction.TemporalExtractor.java

public TaggedText process(String text) throws Exception {
    Date currentTime = Calendar.getInstance(TimeZone.getDefault()).getTime();
    TaggedText taggedText = new TaggedText();
    text = StringEscapeUtils.escapeXml11(text);
    taggedText.setText(text);/*from   w  w  w  .  j a  v a  2s.c om*/
    String timemlOutput = heidelTagger.process(text, currentTime);
    taggedText.setTaggedText(timemlOutput);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    org.w3c.dom.Document doc = builder.parse(new InputSource(new StringReader(timemlOutput)));

    StringBuilder sb = new StringBuilder();
    NodeList timemlNodes = doc.getElementsByTagName("TimeML");
    for (int i = 0; i < timemlNodes.getLength(); i++) {
        NodeList childs = timemlNodes.item(i).getChildNodes();
        for (int j = 0; j < childs.getLength(); j++) {
            Node child = childs.item(j);
            if (child.getNodeType() == Node.TEXT_NODE) {
                sb.append(child.getTextContent());
            } else if (child.getNodeName().equals("TIMEX3")) {
                String timeText = child.getTextContent();
                String timeValueString = child.getAttributes().getNamedItem("value").getNodeValue();
                String normalizedTime = null;
                try {
                    normalizedTime = TEEUtils.normalizeTime(timeValueString);
                } catch (Exception ex) {
                    //logger.log(Level.WARNING, "Error to normalize time: ", ex);
                }
                if (normalizedTime != null) {
                    TimeEvent event = new TimeEvent(sb.length(), sb.length() + timeText.length(),
                            normalizedTime);
                    event.setEventString(timeText);
                    taggedText.getEvents().add(event);
                }
                sb.append(timeText);
            }
            //VERBOSE
            //System.out.println(child.getNodeType() + "\t" + child.getNodeName() + "\t" + child.getTextContent());
            //System.out.println();
        }
    }
    taggedText.setText(sb.toString());
    return taggedText;
}

From source file:com.mi.xserv.XservBase.java

protected int getTimeZoneOffset() {
    // GMT es. italia +1
    TimeZone timezone = TimeZone.getDefault();
    int seconds = timezone.getOffset(Calendar.ZONE_OFFSET) / 1000;
    double minutes = seconds / 60;
    double hours = minutes / 60;
    return (int) hours;
}

From source file:com.whizzosoftware.hobson.scheduler.ical.ICalTaskProvider.java

public ICalTaskProvider(String pluginId, Double latitude, Double longitude) {
    this(pluginId, latitude, longitude, TimeZone.getDefault());
}