java_ Timestamp and date_ Mutual conversion implementation code

1. Definition of timestamp

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

Digital time stamp technology is a variant of digital signature technology. Time is a very important information in e-commerce transaction documents. In a written contract, the date of document signing is as important as the signature, which is the key content to prevent documents from being forged and tampered with. Digital time stamp service (DTS) is one of the online e-commerce security services, which can provide the security protection of date and time information of electronic documents.

Time stamp is an encrypted voucher document, which includes three parts:

Generally speaking, the process of time stamp generation is: the user first encrypts the file requiring time stamp with hash code to form a summary, and then sends the summary to DTS. DTS encrypts (digitally signs) the file after adding the date and time information of receiving the file summary, and then sends it back to the user

The time of signing the document in writing is written by the signatory himself, but the digital timestamp is not. It is added by the certification unit DTS based on the time when DTS receives the document.

2. Convert timestamp to date (or string)

3. Convert date (or string) to timestamp

Operation results:

Format To times:445555000

4. Attention

When defining simpledateformat, newsimpledateformat ("yyyy MM DD HH: mm: SS"); There should be no spaces at the beginning and end of the string. If there are spaces, it is the time corresponding to the conversion. There should also be spaces (the two correspond), for example:

Operation result (error report):

Exception in thread "main"Java. text. ParseException: Unparseable date: "1970-01-06 11:45:55"

Correction:

1、 Gettime () in the date class in Java gets the timestamp. The timestamp generated in Java is accurate to the millisecond level, while in UNIX it is accurate to the second level. Therefore, the timestamp generated in Java needs to be divided by 1000.

2、 Here is the Java code

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>