use of java.util.TimeZone in project platform_frameworks_base by android.
the class DateUtils method getKMLTimestamp.
/**
* Returns timestamp given by param in KML format ie yyyy-mm-ddThh:mm:ssZ,
* where T is the separator between the date and the time and the time zone
* is Z (for UTC)
*
* @return KML timestamp as String
*/
public static String getKMLTimestamp(long when) {
TimeZone tz = TimeZone.getTimeZone("GMT");
Calendar c = Calendar.getInstance(tz);
c.setTimeInMillis(when);
return String.format("%tY-%tm-%tdT%tH:%tM:%tSZ", c, c, c, c, c, c);
}
use of java.util.TimeZone in project iosched by google.
the class TimeUtils method formatShortTime.
public static String formatShortTime(Context context, Date time) {
// Android DateFormatter will honor the user's current settings.
DateFormat format = android.text.format.DateFormat.getTimeFormat(context);
// Override with Timezone based on settings since users can override their phone's timezone
// with Pacific time zones.
TimeZone tz = SettingsUtils.getDisplayTimeZone(context);
if (tz != null) {
format.setTimeZone(tz);
}
return format.format(time);
}
use of java.util.TimeZone in project iosched by google.
the class TimeUtils method formatHumanFriendlyShortDate.
/**
* Returns "Today", "Tomorrow", "Yesterday", or a short date format.
*/
public static String formatHumanFriendlyShortDate(final Context context, long timestamp) {
long localTimestamp, localTime;
long now = getCurrentTime(context);
TimeZone tz = SettingsUtils.getDisplayTimeZone(context);
localTimestamp = timestamp + tz.getOffset(timestamp);
localTime = now + tz.getOffset(now);
long dayOrd = localTimestamp / 86400000L;
long nowOrd = localTime / 86400000L;
if (dayOrd == nowOrd) {
return context.getString(R.string.day_title_today);
} else if (dayOrd == nowOrd - 1) {
return context.getString(R.string.day_title_yesterday);
} else if (dayOrd == nowOrd + 1) {
return context.getString(R.string.day_title_tomorrow);
} else {
return formatShortDate(context, new Date(timestamp));
}
}
use of java.util.TimeZone in project iosched by google.
the class UIUtils method formatSessionSubtitle.
/**
* Format and return the given session time and {@link Rooms} values using {@link
* Config#CONFERENCE_TIMEZONE}.
*/
public static String formatSessionSubtitle(long intervalStart, long intervalEnd, String roomName, StringBuilder recycle, Context context, boolean shortFormat) {
// Determine if the session is in the past
long currentTimeMillis = TimeUtils.getCurrentTime(context);
boolean conferenceEnded = currentTimeMillis > Config.CONFERENCE_END_MILLIS;
boolean sessionEnded = currentTimeMillis > intervalEnd;
if (sessionEnded && !conferenceEnded) {
return context.getString(R.string.session_finished);
}
if (roomName == null) {
roomName = context.getString(R.string.unknown_room);
}
if (shortFormat) {
TimeZone timeZone = SettingsUtils.getDisplayTimeZone(context);
Date intervalStartDate = new Date(intervalStart);
SimpleDateFormat shortDateFormat = new SimpleDateFormat("MMM dd");
DateFormat shortTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
shortDateFormat.setTimeZone(timeZone);
shortTimeFormat.setTimeZone(timeZone);
return shortDateFormat.format(intervalStartDate) + " " + shortTimeFormat.format(intervalStartDate);
} else {
String timeInterval = formatIntervalTimeString(intervalStart, intervalEnd, recycle, context);
return context.getString(R.string.session_subtitle, timeInterval, roomName);
}
}
use of java.util.TimeZone in project j2objc by google.
the class FormatterTest method checkFormat.
private static void checkFormat(String expected, String pattern, int hour) {
TimeZone utc = TimeZone.getTimeZone("UTC");
Calendar c = new GregorianCalendar(utc);
c.set(2013, Calendar.JANUARY, 1, hour, 00);
assertEquals(expected, String.format(Locale.US, "%t" + pattern, c));
assertEquals(expected, String.format(Locale.US, "%T" + pattern, c));
}
Aggregations