List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:Main.java
@SuppressLint("SimpleDateFormat") static String setTime() { // add DateTime to filename Calendar cal = Calendar.getInstance(TimeZone.getDefault()); Date currentLocalTime = cal.getTime(); SimpleDateFormat date = new SimpleDateFormat("HH-mm-ss"); date.setTimeZone(TimeZone.getDefault()); _currentTime = date.format(currentLocalTime); return _currentTime; }
From source file:Main.java
/** * getDateAsString//www .j ava 2 s. c om * Convert a date into a string * * @param date the date * @param format the format in which to return the string * @return the new formatted date string */ public static String getDateAsString(Date date, String format, String timezone) { DateFormat formatter = new SimpleDateFormat(format, Locale.getDefault()); if (timezone == null) { formatter.setTimeZone(TimeZone.getDefault()); } else { formatter.setTimeZone(TimeZone.getTimeZone(timezone)); } return formatter.format(date); }
From source file:Main.java
public static String getGMTTimeString(long millisecond) { Calendar cal = Calendar.getInstance(); int zoneOffsetTime = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); long millisecondsUTC = millisecond - zoneOffsetTime; GMTTimeFormatter.setTimeZone(TimeZone.getDefault()); String strGMTTime = GMTTimeFormatter.format(millisecondsUTC); return strGMTTime; }
From source file:Main.java
public static long getLocalTime(String strLocalTime) { long millisecond = 0; try {/* w ww. java 2s . c om*/ LocalTimeFormatter.setTimeZone(TimeZone.getDefault()); millisecond = LocalTimeFormatter.parse(strLocalTime).getTime(); } catch (ParseException e) { e.printStackTrace(); } return millisecond; }
From source file:Main.java
/** * Since all dates from the database are in UTC, we must convert the local date to the date in * UTC time. This function performs that conversion using the TimeZone offset. * * @param localDate The local datetime to convert to a UTC datetime, in milliseconds. * @return The UTC date (the local datetime + the TimeZone offset) in milliseconds. *//*from w ww . j av a2s . c o m*/ public static long getUTCDateFromLocal(long localDate) { TimeZone tz = TimeZone.getDefault(); long gmtOffset = tz.getOffset(localDate); return localDate + gmtOffset; }
From source file:Main.java
public static String getTimeRemaining(long durationInMilliseconds) { SimpleDateFormat sdf;//from ww w . j a v a 2 s . c o m if (durationInMilliseconds > 1000 * 60 * 60) { sdf = new SimpleDateFormat("HH:mm", Locale.getDefault()); } else { sdf = new SimpleDateFormat("mm:ss", Locale.getDefault()); } return sdf.format(new Date(durationInMilliseconds - TimeZone.getDefault().getRawOffset())); }
From source file:Main.java
/** * Since all dates from the database are in UTC, we must convert the given date * (in UTC timezone) to the date in the local timezone. Ths function performs that conversion * using the TimeZone offset.//from w ww . j a v a2 s.c o m * * @param utcDate The UTC datetime to convert to a local datetime, in milliseconds. * @return The local date (the UTC datetime - the TimeZone offset) in milliseconds. */ public static long getLocalDateFromUTC(long utcDate) { TimeZone tz = TimeZone.getDefault(); long gmtOffset = tz.getOffset(utcDate); return utcDate - gmtOffset; }
From source file:Main.java
/** * This method will return the local time midnight for the provided normalized UTC date. * * @param normalizedUtcDate UTC time at midnight for a given date. This number comes from the * database//w w w . j a v a2s.co m * * @return The local date corresponding to the given normalized UTC date */ private static long getLocalMidnightFromNormalizedUtcDate(long normalizedUtcDate) { /* The timeZone object will provide us the current user's time zone offset */ TimeZone timeZone = TimeZone.getDefault(); /* * This offset, in milliseconds, when added to a UTC date time, will produce the local * time. */ long gmtOffset = timeZone.getOffset(normalizedUtcDate); long localMidnightMillis = normalizedUtcDate - gmtOffset; return localMidnightMillis; }
From source file:com.baifendian.swordfish.common.utils.DateUtils.java
/** * ? */ public static String getDefaultTimeZome() { return TimeZone.getDefault().getID(); }
From source file:DateTimeUtil.java
/** * Return a String value of Now() in a specify format * @param lang lingua di default//w w w .j a va2 s . com * @param format formato della data vedi esempi tsDefaultFormats * @return String value of Now() in a specify format */ public static final String getNowWithFormat(String format, String lang) { Calendar cal = Calendar.getInstance(TimeZone.getDefault()); String DATE_FORMAT = format; SimpleDateFormat sdf = null; if (lang != null) { sdf = new SimpleDateFormat(DATE_FORMAT, new Locale(lang)); } else { sdf = new SimpleDateFormat(DATE_FORMAT); } sdf.setTimeZone(TimeZone.getDefault()); return sdf.format(cal.getTime()); }