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

/**
 * Gives a number only string representing current time ("yyyyMMddHHmmss")
 * /* ww w . ja va  2s. co m*/
 * @return The string representation of current time.
 */
public static String timeNumbers() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date date = new Date();
    return dateFormat.format(date);
}

From source file:Main.java

/**
 * Get the current date and time in SQL date format ("yyyy-MM-dd HH:mm:ss")
 * //from w  w  w  . ja v a 2s .  co  m
 * @return String representing current date and time
 */
public static String timeNow() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    Date date = new Date();
    return dateFormat.format(date);
}

From source file:Main.java

/**
@param time input in seconds and already in proper timezone
@return time in GMT0 timezone/*w w w. ja v  a  2  s  .com*/
 */
public static String getTimeStamp(Context context, long time) {
    java.text.DateFormat df = DateFormat.getTimeFormat(context);
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    return df.format(new Date(time * 1000L));
}

From source file:Main.java

public static String getTime(long millisecond) {
    Date date = new Date(millisecond);
    String time = "";
    if (date != null) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd HH:mm");
        df.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
        time = df.format(date);//  w  w  w .  j  av a2  s. c  o  m
    }
    return time;
}

From source file:Main.java

public static String getDateFromUTC(long timestamp) {
    if (timestamp == 0)
        timestamp = System.currentTimeMillis();
    Date date = new Date(timestamp);
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    cal.setTime(date);//  ww w .j ava2s.co m
    String val = (cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR) + ":"
            + cal.get(Calendar.MINUTE) + (cal.get(Calendar.AM_PM) == 0 ? "AM" : "PM"));

    //      final Date currentTime = new Date();
    //      final SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm:ss a z");
    //      sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    //      String ret = "UTC time: " + sdf.format(currentTime);
    //      System.out.println(ret);

    return val;
}

From source file:Main.java

public static String getServerTime() {
    Calendar calendar = Calendar.getInstance();
    serverDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return serverDateFormat.format(calendar.getTime());
}

From source file:Main.java

public static String formatDateForCookie(Date date) {
    // for http cookie
    final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";

    SimpleDateFormat format = new SimpleDateFormat(PATTERN_RFC1123, Locale.US);
    format.setTimeZone(TimeZone.getTimeZone("GMT"));

    return format.format(date);
}

From source file:Main.java

/**
 * Convert Date to String - For Audio Record FileName ONLY
 * @param date//from   w w  w  . ja v a2 s.co m
 * @param format
 * @return
 */
public static String convertDateToStrForAudioFileName() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.ENGLISH);
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+0000"));
    String dateStr = dateFormat.format(new Date());
    return dateStr;
}

From source file:Main.java

public static String getHours(String dateString) {

    SimpleDateFormat parserSDF = new SimpleDateFormat("HH:mm:ss");
    SimpleDateFormat formater = new SimpleDateFormat("HH:mm");

    parserSDF.setTimeZone(TimeZone.getTimeZone("UTC"));
    formater.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = null;//  w w  w . ja va 2 s  .  c  o  m
    try {
        parserSDF.setTimeZone(TimeZone.getTimeZone("UTC"));
        date = parserSDF.parse(dateString);
    } catch (ParseException e) {
        Log.d(TAG, e.getMessage());
    }

    return formater.format(date);
}

From source file:Main.java

/**
 * Turns a Java date object into a mySQL acceptable date string
 * //w w  w.j  a  v  a2  s. co m
 * @param date
 *            Date object
 * @return mySQL acceptable date string
 */
public static String toSQLDateTimeString(Date date) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    return dateFormat.format(date);
}