Android gets timestamp converted from server to month day

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.