Java time stamp

Source: Internet
Author: User

1 , the definition of time stamp

Timestamp refers to the creation, modification, and access time of the file attributes.  

Digital Timestamp technology is a variant application of digital signature technology. In e-Commerce transaction files, time is a very important information. In a written contract, the date and signature of the document are important to prevent the document from being forged and tampered with. Digital timestamp service (DTS:Digitally timestampservices) is one of the online e-commerce security services, which can provide the security protection of date and time information of electronic documents.

Edit part of this paragraph

time Stamp ( Time-stamp ) is an encrypted credential document that consists of three parts:

(1) Summary of documents requiring time stamping (digest);

(2) The date and time when DTS received the file;

(3) digital signature of DTS.

in general, the process of a timestamp is that the user first encrypts the file that needs to be timestamp with a Hash Code, and then sends the digest to DTS, DTS encrypts the file (digitally signed) and then sends it back to the user after it has joined the date and time information that received the file digest.

The time of the written signature is written by the signer himself, and the digital timestamp is not, it is added by the Certification Unit DTS , based on the time that DTS received the file.

2 , the timestamp is converted to Date ( or String )

    // timestamp converted to style= word-wrap:normal" line-height:19px;font-family: ' Courier new ', Color:rgb (127, font-size:13px); Word-wrap:normal;line-height:19px;font-family: Color:rgb (127, word-wrap:normal;line-height:19px;font-family: ' Courier new ', Color:rgb (127, font-size:13px);

        simpledateformat format =     new  simpledateformat (  " Yyyy-mm-dd HH: Mm:ss "  

Long time=new Long (445555555);

String d = format.format (time);

Date Date=format.parse (d);

        system. ou T " Format to String (Date): "

System . out . println ("Format to Date:"+date);

operation Result:

Format to String (Date): 1970-01-06 11:45:55

Format to Date:tue Jan 11:45:55 CST 1970

3 , Date ( or String ) into a timestamp

//date or String conversion to timestamp

        simpledateformat format =     new  simpledateformat (  " Yyyy-mm-dd HH: Mm:ss "  

String time="1970-01-06 11:45:55";

Date date = Format.parse (time);

System . out . Print ("Format to Times:"+date.gettime ());

Operation Result:

Format to times:445555000

4 , Attention

  definitionSimpleDateFormatwhenNewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");inside the string can not have a space, there is a space that is used to convert the corresponding time space should also have a space (the two are corresponding), such as:

/ /date string Convert to timestamp

        simpledateformat format =     new  simpledateformat (  " Yyyy-mm-dd HH: Mm:ss "  

String time="1970-01-06 11:45:55";

Date date = Format.parse (time);

System . out . Print ("Format to Times:"+date.gettime ());

Operation result (Error):

Exception in thread "main" java.text.ParseException : unparseable Date: "1970-01-06 11:45:55"

Correct:

     string Convert to timestamp

        simpledateformat format =     new  simpledateformat (  " Yyyy-mm-dd HH: Mm:ss "  

String time="1970-01-06 11:45:55"; // Note: After correction, there are also spaces around here.

Date date = Format.parse (time);

System . out . Print ("Format to Times:"+date.gettime ());

operation Result:

Format to times:445555000


Java 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.