Java date to timestamp, timestamp changed to date

Source: Internet
Author: User

Package date;

Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;

public class Test {
public static void Main (string[] args) {
Date d = new Date ();
String begindate = "1435845268096";

SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");

String SD = Sdf.format (New Date (Long.parselong (begindate))); Time Stamp Conversion Date
System.out.println (D.gettime ());
SYSTEM.OUT.PRINTLN (SD);
String SDT = Sdf.format (d);
SYSTEM.OUT.PRINTLN ("Current system time:" + SDT);
SYSTEM.OUT.PRINTLN ("System timestamp:" + d.gettime ());
System.out.println ("Timestamp conversion date:" + SD);
try {
SimpleDateFormat SF = new SimpleDateFormat ("Yyyy-mm-dd");
D = Sf.parse ("2015-07-03 22:20:20");//date converted to timestamp
} catch (ParseException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Long timestemp = D.gettime ();
System.out.println ("Date conversion timestamp:" + timestemp);

Test T = new Test ();
System.out.println (">>>>>>>>>>>>>//timestamp conversion date >"
+ t.stamptotime ("1435845268096"));
System.out.println ("<<<<<<<<<<<<<<<<//date converted to timestamp <"
+ T.timetostamp ("2015-07-03"));
}

/*//Timestamp conversion date */
public string Stamptotime (string stamp) {
String sd = "";
Date d = new Date ();
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd");
SD = Sdf.format (New Date (Long.parselong (stamp))); Time Stamp Conversion Date
return SD;
}

/*/Date converted to timestamp */
Public long Timetostamp (String timers) {
Date d = new Date ();
Long timestemp = 0;
try {
SimpleDateFormat SF = new SimpleDateFormat ("Yyyy-mm-dd");
D = sf.parse (timers);//date converted to timestamp
} catch (ParseException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
Timestemp = D.gettime ();
return timestemp;
}
}

Java date to timestamp, timestamp changed to date

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.