List of usage examples for java.util TimeZone getTimeZone
public static TimeZone getTimeZone(ZoneId zoneId)
From source file:Main.java
/** * Always get Taipei time (GMT+8)//www .j a va 2s . c o m * * @return Calendar */ public static Calendar getNowTime() { //Log.d(TAG, Locale.TAIWAN.toString()); //return Calendar.getInstance(Locale.TAIWAN); return Calendar.getInstance(TimeZone.getTimeZone("GMT+8")); }
From source file:Main.java
public static DateFormat GetFileNameDateFormatter() { Locale loc = new Locale("en", "US"); SimpleDateFormat df = new SimpleDateFormat("MM.dd.yy.h.mm.ss", loc); df.setTimeZone(TimeZone.getTimeZone("UTC")); return df;// w w w. j av a 2 s . c om }
From source file:Main.java
public static Date getDateFromFormattedStringInGMT(String str) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); Date date = null;//from w w w.j av a 2 s .c o m try { date = simpleDateFormat.parse(str); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
private static String getTime() { format.setLenient(false);/*from ww w . j ava 2 s .c om*/ format.setTimeZone(TimeZone.getTimeZone("GMT+8")); return format.format(Calendar.getInstance().getTime()); }
From source file:Main.java
public static Date getDateFromString(String inputString) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = null;/*from w ww .ja va 2s . c o m*/ try { date = sdf.parse(inputString); } catch (ParseException e) { e.printStackTrace(); } return date; }
From source file:Main.java
/** * TO get current time(GMT)//w w w . j a va 2 s. c o m * * @return current time at specific time zone */ public static String UtcDateNow() { SimpleDateFormat formatUTC = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); formatUTC.setTimeZone(TimeZone.getTimeZone("EST5EDT")); return formatUTC.format(new Date().getTime()); }
From source file:Main.java
public static long parseTimeToLong(String time) { if (null == time) return System.currentTimeMillis(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault()); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); java.util.Date d;//from w w w .j a v a 2s. c o m try { d = sdf.parse(time); return d.getTime(); } catch (Exception e) { e.printStackTrace(); } return System.currentTimeMillis(); }
From source file:Main.java
private static SimpleDateFormat getApiSimpleDateFormat() { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(API_DATE_FORMAT, Locale.getDefault()); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return simpleDateFormat; }
From source file:Main.java
public static String formatTime(final long totalSeconds, final int timer) { if (timer == 0) { final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); sdf.setTimeZone(TimeZone.getTimeZone("GMT+0")); return sdf.format(new Date(totalSeconds * 1000)); } else {// w w w . j av a2 s .c o m String seconds = Integer.toString((int) (totalSeconds % 60)); String minutes = Integer.toString((int) (totalSeconds / 60)); if (seconds.length() < 2) { seconds = "0" + seconds; } if (minutes.length() < 2) { minutes = "0" + minutes; } return minutes + ":" + seconds; } }
From source file:Main.java
private static String createDate(Date date, String defaultFormat, Boolean utc) { SimpleDateFormat gmtFormat = new SimpleDateFormat(); gmtFormat.applyPattern(defaultFormat); TimeZone gmtTime = (utc) ? TimeZone.getTimeZone("GMT") : TimeZone.getDefault(); gmtFormat.setTimeZone(gmtTime);/* w w w . j a v a 2 s .com*/ return gmtFormat.format(date); }