The original teacher's time conversion problem (slag-off day)

Source: Internet
Author: User

Package

Import Java.sql.Timestamp;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;

Import Org.junit.Test;

Timestamp timestamp and SimpleDateFormat conversion date format
@Test
public void Timestamptest () {

01: Date converted to string
Date date = new Date ();
Date.getdate () was awarded the 1970-01-01 08:00:00.011
Date.gettime () Gets the number of milliseconds from 1970-01-01 08:00:00.011 onwards to the present

Timestamp can convert the resulting number of milliseconds into the current system time
Timestamp Timestamp =null;//New Timestamp (Date.gettime ());
Output 2015-12-11 08:41:22.391, including number of milliseconds
System.out.println ("Number of milliseconds:" +date.gettime ());
The number of milliseconds after the removal time
Set the time format first
SimpleDateFormat format=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
System.currenttimemillis () and Date.gettime () are the same number of milliseconds obtained
Timestamp=new timestamp (System.currenttimemillis ());
Converts a formatted time to a string type
String Nowtime=format.format (timestamp);
System.out.println ("Converted time:" +nowtime);



02:string Convert to date


String Time=format.format (date);
System.out.println (time);
Timestamp=timestamp.valueof (time);
SYSTEM.OUT.PRINTLN (timestamp);
}

The original teacher's time conversion problem (slag-off 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.