Java SimpleDateFormat conversion between date and time stamp

Source: Internet
Author: User

Self-summary, what is not satisfied with the place, you can help correct the supplement, thank you!

Purpose: SimpleDateFormat class can be a very casual combination of date and time format, more than simply yyyy-mm-dd this format

Nonsense not much to say on the code

Test class Datetest

 Packagecom.core.test;Importjava.text.ParseException;ImportJava.text.SimpleDateFormat;Importjava.util.Date; Public classDatetest { Public Static voidMain (string[] args)throwsparseexception {SimpleDateFormat sdf0=NewSimpleDateFormat ("YyyyMMdd"); SimpleDateFormat SDF1=NewSimpleDateFormat ("Yyyy-mm-dd"); SimpleDateFormat SDF2=NewSimpleDateFormat ("yyyy mm month DD Day"); SimpleDateFormat sdf3=NewSimpleDateFormat ("ddmmyyyy"); String TIME0= "20140916"; String time1= "2014-09-16"; String time2= "September 16, 2014"; String Time3= "16092014";        Convertstamp (sdf0, TIME0);        Convertstamp (SDF1, time1);        Convertstamp (SDF2, time2);        Convertstamp (SDF3, Time3); LongStamp = 1410796800000L;        Convertdate (sdf0, stamp);        Convertdate (SDF1, stamp);        Convertdate (SDF2, stamp);    Convertdate (SDF3, stamp); }    //Date converted to timestamp     Public Static voidConvertstamp (simpledateformat format, String time)throwsparseexception {Date Date=Format.parse (time);    System.out.println (Date.gettime ()); }    //time stamp converted to date     Public Static voidConvertdate (SimpleDateFormat SDF,Longstamp) {String Date= Sdf.format (NewDate (stamp));    SYSTEM.OUT.PRINTLN (date); }}

Operation Result:

1410796800000141079680000014107968000001410796800000201409162014-09-16September 16, 2014 16092014

SimpleDateFormat is very flexible, haha.

Java SimpleDateFormat conversion between date and time stamp

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.