New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); = Sdf.parse ("2018-06-05 13:01:25"); System.out.println (Date.gettime ()); System.out.println (Sdf.format (Date.gettime ()));
This example is sufficient to illustrate how data of date type is converted to a long type
How a long type of date is converted to date
In particular, the third-party interface, many interface parameters in addition to the signature has a timestamp, the timestamp is usually expressed in a long type of time (this refers to the date to a long type)
Security is the main consideration.
Date dt =new date (); SYSTEM.OUT.PRINTLN (DT); Format: Wed Jul 09:28:19 CST 2016//format: 2018-6-24 String formatdate = null; FormatDate = Dateformat.getdateinstance (). Format (DT); System.out.println (formatdate); Format: Wednesday, June 24, 2018 FormatDate = Dateformat.getdateinstance (dateformat.full). Format (DT); System.out.println (formatdate); Format 24-hour system: 2018-06-24 09:39:58 DateFormat dformat = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); HH denotes a 24-hour system; formatdate = Dformat.format (DT); System.out.println (formatdate); Format 12-hour system: 2018-06-24 09:42:44 DateFormat dFormat12 = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss"); HH denotes a 12-hour system; formatdate = Dformat12.format (DT); System.out.println (formatdate); Format Remove delimiter 24-hour system: 20160706094533 dateformat DFORMAT3 = new SimpleDateFormat ("Yyyymmddhhmmss"); FormatDate = Dformat3.format (DT); System.out.println (formatdate); Format to Long: 1467770970 long ltime = Dt.gettime ()/1000; System.out.println (Ltime); Format long type to date, and then to string:1464710394-ltime2*1000, 2018-06-24 23:59:54 long ltime2 = 1464710394; SimpleDateFormat Lsdformat = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); Date lDate = new Date (ltime2*1000); String lstrdate = Lsdformat.format (lDate); System.out.println (lstrdate); format string to date: 2018-06-24 10:17:48-Wed Jul 10:17:48 CST, string strdate = "2018-06-24 10:17:48"; SimpleDateFormat Lsdstrformat = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); try {Date StrD = Lsdstrformat.parse (strdate); System.out.println (StrD); } catch (ParseException e) {e.printstacktrace (); }
The above is a more commonly used time type conversion, usually signature is commonly used is a long type of time stamp, pay more, for security reasons.
As for string types, it is common to create time, update time, and more.
Java Time Conversion