Search in sources :

Example 96 with DateFormat

use of java.text.DateFormat in project j2objc by google.

the class NativeDecimalFormatTest method testZeroHour.

// Verify formatting a date with a format string with zeros.
public void testZeroHour() throws Exception {
    DateFormat sdf = new SimpleDateFormat("HH:mm:ss");
    String timeString = "00:00:23";
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    // Issue found a ParseException was thrown here.
    Date date = sdf.parse(timeString);
    // Only check seconds, as hour and date changes depending on timezone.
    assertTrue(date.toString().contains(":23"));
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 97 with DateFormat

use of java.text.DateFormat in project jimfs by google.

the class PathURLConnection method connect.

@Override
public void connect() throws IOException {
    if (stream != null) {
        return;
    }
    Path path = Paths.get(toUri(url));
    long length;
    if (Files.isDirectory(path)) {
        // Match File URL behavior for directories by having the stream contain the filenames in
        // the directory separated by newlines.
        StringBuilder builder = new StringBuilder();
        try (DirectoryStream<Path> files = Files.newDirectoryStream(path)) {
            for (Path file : files) {
                builder.append(file.getFileName()).append('\n');
            }
        }
        byte[] bytes = builder.toString().getBytes(UTF_8);
        stream = new ByteArrayInputStream(bytes);
        length = bytes.length;
    } else {
        stream = Files.newInputStream(path);
        length = Files.size(path);
    }
    FileTime lastModified = Files.getLastModifiedTime(path);
    String contentType = MoreObjects.firstNonNull(Files.probeContentType(path), DEFAULT_CONTENT_TYPE);
    ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
    builder.put("content-length", "" + length);
    builder.put("content-type", contentType);
    if (lastModified != null) {
        DateFormat format = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
        format.setTimeZone(TimeZone.getTimeZone("GMT"));
        builder.put("last-modified", format.format(new Date(lastModified.toMillis())));
    }
    headers = builder.build();
}
Also used : Path(java.nio.file.Path) FileTime(java.nio.file.attribute.FileTime) Date(java.util.Date) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) SimpleDateFormat(java.text.SimpleDateFormat)

Example 98 with DateFormat

use of java.text.DateFormat 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 99 with DateFormat

use of java.text.DateFormat 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 100 with DateFormat

use of java.text.DateFormat in project j2objc by google.

the class DateFormatTest method test_getNumberFormat.

/**
	 * @tests java.text.DateFormat#getNumberFormat()
	 */
public void test_getNumberFormat() {
    DateFormat format = DateFormat.getInstance();
    NumberFormat nf1 = format.getNumberFormat();
    NumberFormat nf2 = format.getNumberFormat();
    assertTrue("NumberFormats not identical", nf1 == nf2);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) NumberFormat(java.text.NumberFormat)

Aggregations

DateFormat (java.text.DateFormat)646 SimpleDateFormat (java.text.SimpleDateFormat)486 Date (java.util.Date)315 ParseException (java.text.ParseException)132 Calendar (java.util.Calendar)78 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)48 IOException (java.io.IOException)43 File (java.io.File)31 HashMap (java.util.HashMap)27 GregorianCalendar (java.util.GregorianCalendar)24 TimeZone (java.util.TimeZone)23 Locale (java.util.Locale)18 Timestamp (java.sql.Timestamp)17 List (java.util.List)14 InputStream (java.io.InputStream)12 DateTime (org.joda.time.DateTime)11 Map (java.util.Map)10 Matcher (java.util.regex.Matcher)8 TestBean (org.springframework.tests.sample.beans.TestBean)8