Transform with Java-related classes. The code is as follows:
Calendar calendar = calendar.getinstance (); + ); // MSS is the timestamp obtained from the server New SimpleDateFormat ("yyyy-mm-dd HH:mm:ss"); = Sf.format (calendar.gettime ()); // date is the time that has been converted.
/** * Timestamp converted into a date format string * @param seconds exact to the second string * @param formatstr * @return*/ Public Staticstring timestamp2date (string seconds,string format) {if(Seconds = =NULL|| Seconds.isempty () | | Seconds.equals ("NULL")){ return ""; } if(Format = =NULL|| Format.isempty ()) format ="YYYY-MM-DD HH:mm:ss"; SimpleDateFormat SDF=NewSimpleDateFormat (format); returnSdf.format (NewDate (Long.valueof (seconds+" the"))); } /** * Date format string converted to Timestamp * @param date string dates * @param format such as: Yyyy-mm-dd HH:MM:SS * @return*/ Public Staticstring Date2timestamp (string date_str,string format) {Try{SimpleDateFormat SDF=NewSimpleDateFormat (format); returnString.valueof (Sdf.parse (DATE_STR). GetTime ()/ +); } Catch(Exception e) {e.printstacktrace (); } return ""; } /** * Get current timestamp (accurate to seconds) * @return*/ Public StaticString TimeStamp () {LongTime =System.currenttimemillis (); String T= String.valueof (time/ +); returnT; } //Output Result://timestamp=1417792627//date=2014-12-05 23:17:07//1417792627 Public Static voidMain (string[] args) {String TimeStamp=TimeStamp (); System. out. println ("timestamp="+TimeStamp); String Date= Timestamp2date (TimeStamp,"YYYY-MM-DD HH:mm:ss"); System. out. println ("date="+date); String TIMESTAMP2= Date2timestamp (date,"YYYY-MM-DD HH:mm:ss"); System. out. println (TIMESTAMP2); } //convert timestamp to time division secondsString date ="142925"; SimpleDateFormat DateFormat=NewSimpleDateFormat ("HH:mm:ss"); Date currenttime=NewDate (); String datestring=Dateformat.format (currenttime); System. out. println (datestring);
Android gets timestamp converted from server to month day