Conversion between time and time stamps in Java

Source: Internet
Author: User
Tags date1

1  PackageCom.test.one;2 3 Importjava.text.ParseException;4 ImportJava.text.SimpleDateFormat;5 Importjava.util.Date;6 7  Public classTimeone {8      Public Static voidMain (string[] args)throwsException {9String date1 = "2016-05-22 15:11:48";Ten         //Call Method: Convert time to timestamp OneTimeone time =NewTimeone (); AString token =Time . Timechangetoken (date1); -System.out.println ("Time converted to timestamp:" +date1+ "----->" +token); -         //call a method to convert a timestamp into a time theString date =Time . Tokenchangetoken (token); -System.out.println ("Timestamp converted to time:" +token+ "----->" +date); -     } -     //time converted to timestamp (specified) +      PublicString Timechangetoken (string date)throwsparseexception{ - String token; +SimpleDateFormat SF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); ADate da =sf.parse (date); atLong time =da.gettime (); -token =string.valueof (time); -         returntoken; -     } -     //Convert a timestamp to a specific time -      Publicstring Tokenchangetoken (String token) { in String date; -SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); toLong time =NewLong (token); +Date =Sdf.format (time); -         returndate; the          *     } $}

Conversion between time and time stamps in Java

Related Article

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.