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);
}
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);
}
}
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);
}
}
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;
}
}
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;
}
Aggregations