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:Main.java

public static LocalTime getCurrentTime() {
    return new DateTime(DateTimeZone.forTimeZone(TimeZone.getDefault())).toLocalTime();
}

From source file:Main.java

/**
 * @NAME getSimpleTZTag<br>//from  ww  w .ja  v a  2s .c o  m
 *   getSimpleTZTag
 */
public static String getSimpleTZTag() {
    try {
        TimeZone tz = TimeZone.getDefault();
        String s = "tz." + tz.getDisplayName(false, TimeZone.SHORT) + "tzid." + tz.getID();

        return s;
    } catch (Exception e) {
        return "";
    }
}

From source file:Main.java

public static Long getToday() {
    Calendar today = Calendar.getInstance();
    today.setTimeZone(TimeZone.getDefault());

    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.HOUR_OF_DAY, 1);
    today.set(Calendar.MILLISECOND, 0);

    // FOR DEBUG/*from   www .j a v  a  2s  .com*/
    //today.set(Calendar.DAY_OF_YEAR, today.get(Calendar.DAY_OF_YEAR) + 1);

    return today.getTimeInMillis();
}

From source file:Main.java

public static Long getYesterday() {
    Calendar yesterday = Calendar.getInstance();
    yesterday.setTimeZone(TimeZone.getDefault());

    yesterday.set(Calendar.SECOND, 0);
    yesterday.set(Calendar.MINUTE, 0);
    yesterday.set(Calendar.HOUR_OF_DAY, 1);
    yesterday.set(Calendar.MILLISECOND, 0);

    int day = yesterday.get(Calendar.DAY_OF_YEAR);

    yesterday.set(Calendar.DAY_OF_YEAR, day - 1);

    return yesterday.getTimeInMillis();
}

From source file:Main.java

public static Date convertLocalToUTC(Date local) {
    Date now = new Date(System.currentTimeMillis());
    Date result = new Date(local.getTime() - TimeZone.getDefault().getOffset(now.getTime()));
    return result;
}

From source file:Main.java

public static Calendar calendarFromDays(long days) {
    return calendarLocal_FromMilliseconds(days * MILLISECONDS_PER_DAY - TimeZone.getDefault().getRawOffset());
}

From source file:Main.java

public static String getDateString(long time) {
    Calendar date = Calendar.getInstance();
    time = time * 1000;/*from   w w  w  .  j  a  v a 2  s.c o m*/
    long targetTime = time - TimeZone.getDefault().getRawOffset();
    date.setTimeInMillis(targetTime);

    SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
    String dateString = dateformat.format(date.getTime());
    return dateString;
}

From source file:Main.java

public static String getTimestamp() {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
    sdf.setTimeZone(TimeZone.getDefault());
    String tmp = sdf.format(new Date());
    tmp = tmp.substring(0, 22) + ":" + tmp.substring(22);
    return tmp;/*from  w  ww . j av a 2 s. c om*/
}

From source file:Main.java

public static SimpleDateFormat getEndDateTimeInTimezone(String timezone) {
    SimpleDateFormat format = new SimpleDateFormat("h:mm a");
    if (timezone == null || timezone.isEmpty()) {
        format.setTimeZone(TimeZone.getDefault());
    } else//  w  w w .j  ava 2  s  .  c o m
        format.setTimeZone(TimeZone.getTimeZone("GMT+" + timezone));
    return format;
}

From source file:Main.java

public static String getTimeAndDate(long j) {
    try {/*  w w w  .jav a 2s . c  o  m*/
        Calendar instance = Calendar.getInstance();
        TimeZone timeZone = TimeZone.getDefault();
        instance.setTimeInMillis(j);
        instance.add(14, timeZone.getOffset(instance.getTimeInMillis()));
        String format = new SimpleDateFormat(" dd, MMM yyyy").format(instance.getTime());
        Time time = new Time();
        time.set(j);
        return time.format("%H:%M") + format;
    } catch (Exception e) {
        return "";
    }
}