Instance code for Java time conversion
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import Java.util.Calendar;
Import Java.util.Date;
/** * Created by Edward on 2016/6/30. * * public class Timeutil {/** * converts 1467341232351 to the specified format "Yyyy-mm-dd HH:mm:ss." SSS "* @param time" 1467342217645 "* @param pattern" yyyy-mm-dd HH:mm:ss. SSS "* @return 2016-07-01 11:03:37.645/public static string Parselongtime2string (string time, String Patt
ern) {Calendar calendar = calendar.getinstance ();
Calendar.settimeinmillis (long.valueof (time));
Return to new SimpleDateFormat (pattern). Format (Calendar.gettime ()); /** * Converts a string in the specified format to a long * @param time "2016-07-01 10:52:41.792" * @param pattern "yyyy-mm-dd HH:mm:ss. SSS "* @return 1467341561792 */public static long Parsestring2longtime (string time, String pattern) {D
ate date = null;
try {date = new SimpleDateFormat (pattern). Parse (time); catch (ParseException e) {E.printstackTrace ();
return Date.gettime ();
public static void Main (string[] args) {Calendar calendar = calendar.getinstance ();
System.out.println (Calendar.gettimeinmillis ()); System.out.println (timeutil.parselongtime2string string.valueof (Calendar.gettimeinmillis ()), Yyyy-mm-dd HH:mm: Ss.
SSS ")); System.out.println (Timeutil.parsestring2longtime ("2016-07-01 10:52:41.792", "Yyyy-mm-dd HH:mm:ss.")
SSS ")); }
}
The above Java Time Conversion example code is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.