/** * Obtains a specific time from the number of seconds, 24-hour system, such as 2016-12-12 23:23:15 * @param second * @return/public static String Second2moment24 (long s
Econd) {Date date = new Date (second*1000);
SimpleDateFormat ft = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Ft.settimezone (Timezone.gettimezone ("gmt+8"));
return Ft.format (date); /** * To obtain a specific time from the number of seconds, 12-hour system, such as 2016-12-12 23:23:15 * @param second * @return/public static String second2moment12 (lon
G second) {Date date = new Date (second*1000);
SimpleDateFormat ft = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");
Ft.settimezone (Timezone.gettimezone ("gmt+8"));
return Ft.format (date); /** * Obtain a specific time from the number of seconds, 24-hour system, such as 2016-12-12 23:23:15 * @param second * @return/public static String Second2momentgmt0 (l
Ong second) {Date date = new Date (second*1000);
SimpleDateFormat ft = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Ft.settimezone (Timezone.gettimezone ("gmt+0")); return Ft.format (date);
/** * from a specific time, such as 2016-12-12 23:23:15, get the number of seconds * @param time * @return/public static long Gettimestamp (String time) {
SimpleDateFormat SimpleDateFormat = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Simpledateformat.settimezone (Timezone.gettimezone ("gmt+8"));
Date date = null;
try {date = Simpledateformat.parse (time);
catch (ParseException e) {return 0;
Long timestemp = Date.gettime ()/1000;
return timestemp;
}
1, why the conversion from System.currenttimemillis () to standard time format will be 12 hours. For example, the current time is 2016-12-19 21:36:20, call second2moment12 (System.currenttimemillis ()/1000), the output is 2016-12-19 09:36:20. The reason is mixed 12-hour system and 24-hour system, SimpleDateFormat should use "
YYYY-MM-DD HH:mm:ss"
2, why the conversion from System.currenttimemillis () to standard time format will be 8 hours. For example, the current time is 2016-12-19 21:36:20, call Second2momentgmt0 (System.currenttimemillis ()/1000), the output is 2016-12-19 13:36:20.
Using System.currenttimemillis () to obtain the system time is the international Standard Time, is 0 time zone times. The reason may be that SimpleDateFormat did not set a time zone, Ft.settimezone (
Timezone.gettimezone ("gmt+8"))。
3, how from a time string such as 2016-12-19 13:36:20 to obtain its seconds, can be used to compare the time of the morning and evening, such as the current time is 2016-12-19 21:36:20, call Gettimestamp ("2016-12-19 21:36:20" ), the output is 1482154580.