Search in sources :

Example 6 with TimeZone

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);
}
Also used : TimeZone(java.util.TimeZone) Calendar(java.util.Calendar)

Example 7 with TimeZone

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);
}
Also used : TimeZone(java.util.TimeZone) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat)

Example 8 with TimeZone

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));
    }
}
Also used : TimeZone(java.util.TimeZone) Date(java.util.Date)

Example 9 with TimeZone

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);
    }
}
Also used : TimeZone(java.util.TimeZone) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 10 with TimeZone

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));
}
Also used : TimeZone(java.util.TimeZone) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar)

Aggregations

TimeZone (java.util.TimeZone)577 Date (java.util.Date)140 Calendar (java.util.Calendar)137 SimpleTimeZone (java.util.SimpleTimeZone)89 Test (org.junit.Test)85 SimpleDateFormat (java.text.SimpleDateFormat)69 Locale (java.util.Locale)69 GregorianCalendar (java.util.GregorianCalendar)56 ArrayList (java.util.ArrayList)32 DateFormat (java.text.DateFormat)24 ParseException (java.text.ParseException)23 IOException (java.io.IOException)20 Map (java.util.Map)15 HashSet (java.util.HashSet)13 PreparedStatement (java.sql.PreparedStatement)11 HashMap (java.util.HashMap)11 DateTimeZone (org.joda.time.DateTimeZone)11 Support_TimeZone (tests.support.Support_TimeZone)10 Resources (android.content.res.Resources)9 SQLException (java.sql.SQLException)9