Search in sources :

Example 76 with DateFormat

use of java.text.DateFormat in project okhttp by square.

the class CacheTest method formatDate.

private String formatDate(Date date) {
    DateFormat rfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
    rfc1123.setTimeZone(TimeZone.getTimeZone("GMT"));
    return rfc1123.format(date);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 77 with DateFormat

use of java.text.DateFormat in project jpHolo by teusink.

the class Globalization method getStringtoDate.

/*
     * @Description: Parses a date formatted as a string according to the client's user
     * preferences and calendar using the time zone of the client and returns
     * the corresponding date object
     * @Return: JSONObject
     *          Object.year {Number}: The four digit year
     *          Object.month {Number}: The month from (0 - 11)
     *          Object.day {Number}: The day from (1 - 31)
     *          Object.hour {Number}: The hour from (0 - 23)
     *          Object.minute {Number}: The minute from (0 - 59)
     *          Object.second {Number}: The second from (0 - 59)
     *          Object.millisecond {Number}: The milliseconds (from 0 - 999), not available on all platforms
     *
     * @throws: GlobalizationError.PARSING_ERROR
    */
private JSONObject getStringtoDate(JSONArray options) throws GlobalizationError {
    JSONObject obj = new JSONObject();
    Date date;
    try {
        //get format pattern from android device (Will only have device specific formatting for short form of date) or options supplied
        DateFormat fmt = new SimpleDateFormat(getDatePattern(options).getString("pattern"));
        //attempt parsing string based on user preferences
        date = fmt.parse(options.getJSONObject(0).get(DATESTRING).toString());
        //set Android Time object
        Time time = new Time();
        time.set(date.getTime());
        //return properties;
        obj.put("year", time.year);
        obj.put("month", time.month);
        obj.put("day", time.monthDay);
        obj.put("hour", time.hour);
        obj.put("minute", time.minute);
        obj.put("second", time.second);
        obj.put("millisecond", Long.valueOf(0));
        return obj;
    } catch (Exception ge) {
        throw new GlobalizationError(GlobalizationError.PARSING_ERROR);
    }
}
Also used : JSONObject(org.json.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Time(android.text.format.Time) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) JSONException(org.json.JSONException)

Example 78 with DateFormat

use of java.text.DateFormat in project cordova-android-chromeview by thedracle.

the class Globalization method getStringtoDate.

/*
     * @Description: Parses a date formatted as a string according to the client's user
     * preferences and calendar using the time zone of the client and returns
     * the corresponding date object
     * @Return: JSONObject
     *          Object.year {Number}: The four digit year
     *          Object.month {Number}: The month from (0 - 11)
     *          Object.day {Number}: The day from (1 - 31)
     *          Object.hour {Number}: The hour from (0 - 23)
     *          Object.minute {Number}: The minute from (0 - 59)
     *          Object.second {Number}: The second from (0 - 59)
     *          Object.millisecond {Number}: The milliseconds (from 0 - 999), not available on all platforms
     *
     * @throws: GlobalizationError.PARSING_ERROR
    */
private JSONObject getStringtoDate(JSONArray options) throws GlobalizationError {
    JSONObject obj = new JSONObject();
    Date date;
    try {
        //get format pattern from android device (Will only have device specific formatting for short form of date) or options supplied
        DateFormat fmt = new SimpleDateFormat(getDatePattern(options).getString("pattern"));
        //attempt parsing string based on user preferences
        date = fmt.parse(options.getJSONObject(0).get(DATESTRING).toString());
        //set Android Time object
        Time time = new Time();
        time.set(date.getTime());
        //return properties;
        obj.put("year", time.year);
        obj.put("month", time.month);
        obj.put("day", time.monthDay);
        obj.put("hour", time.hour);
        obj.put("minute", time.minute);
        obj.put("second", time.second);
        obj.put("millisecond", new Long(0));
        return obj;
    } catch (Exception ge) {
        throw new GlobalizationError(GlobalizationError.PARSING_ERROR);
    }
}
Also used : JSONObject(org.json.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Time(android.text.format.Time) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) JSONException(org.json.JSONException)

Example 79 with DateFormat

use of java.text.DateFormat in project syncany by syncany.

the class Client method getApplicationDate.

public static Date getApplicationDate() {
    try {
        DateFormat dateFormat = new SimpleDateFormat(APPLICATION_PROPERTIES_DATE_FORMAT, Locale.ENGLISH);
        Date applicationDate = dateFormat.parse(applicationProperties.getProperty(APPLICATION_PROPERTIES_DATE_KEY));
        return applicationDate;
    } catch (Exception e) {
        return null;
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 80 with DateFormat

use of java.text.DateFormat in project bazel by bazelbuild.

the class ZipUtil method unixToDosTime.

/** Converts a unix timestamp into a 32-bit DOS timestamp. */
static int unixToDosTime(long timeMillis) {
    Calendar time = Calendar.getInstance();
    time.setTimeInMillis(timeMillis);
    if (!isValidInDos(timeMillis)) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        throw new IllegalArgumentException(String.format("%s is not representable in the DOS time" + " format. It must be in the range %s to %s", df.format(time.getTime()), df.format(new Date(DOS_EPOCH)), df.format(new Date(MAX_DOS_DATE))));
    }
    int dos = time.get(Calendar.SECOND) / 2;
    dos |= time.get(Calendar.MINUTE) << DOS_MINUTE_OFFSET;
    dos |= time.get(Calendar.HOUR_OF_DAY) << DOS_HOUR_OFFSET;
    dos |= time.get(Calendar.DAY_OF_MONTH) << DOS_DAY_OFFSET;
    dos |= (time.get(Calendar.MONTH) + 1) << DOS_MONTH_OFFSET;
    dos |= (time.get(Calendar.YEAR) - 1980) << DOS_YEAR_OFFSET;
    return dos;
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

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