1, the definition of time stamp
Timestamp refers to the creation, modification, and access time in file attributes.
Digital timestamp technology is a kind of application of digital signature technology. Time is a very important information in the electronic commerce transaction file. In a written contract, the date and signature of the document are important to prevent the forgery and tampering of the documents. Digital timestamp service (dts:digital time stamp services) is one of the online e-commerce security services, which can provide the security protection of the date and time information of electronic files.
A timestamp (Time-stamp) is an encrypted credential document that consists of three parts:
- Summary of documents requiring timestamp (digest);
- The date and time that DTS received the file;
- The digital signature of DTS.
In general, the timestamp process is that the user first encrypts a file that needs to be stamped with a hash code to form a summary, and then sends the digest to Dts,dts to encrypt (digitally sign) the file after adding the date and time information that received the summary of the file, and then send it back to the user.
The time of the written signature document is written by the signer himself, and the digital timestamp is not, it is added by DTS of the authentication unit, and the time of receiving the document is based on DTS.
2, timestamp converted to date (or String)
The timestamp is converted to sting or date
simpledateformat format = Newsimpledateformat ("Yyyy-mm-dd HH:mm:ss");
Long Time=newlong (445555555);
String d = format.format (time);
Date Date=format.parse (d);
System.out.println ("Format to String (Date):" +d);
System.out.println ("Format to Date:" +date);
Run Result:
format to String (Date): 1970-01-06 11:45:55
Format to date:tue the 11:45:55 CST 1970
3, date (or String) converted to timestamp
Date or string is converted to timestamp
simpledateformat format = Newsimpledateformat ("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 ());
Run Result:
Format to times:445555000
4. Note
Define SimpleDateFormat Newsimpledateformat ("Yyyy-mm-dd HH:mm:ss"); inside the string can not have a space, there is a space that is the conversion of the corresponding time space to have a space (the two are corresponding), such as:
Date or string is converted to timestamp
simpledateformat format = Newsimpledateformat ("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 ());
Run result (Error):
Exception in thread "main" Java.text.ParseException:Unparseable Date: "1970-01-06 11:45:55"
Correct:
Date or string is converted to timestamp
simpledateformat format = Newsimpledateformat ("Yyyy-mm-dd HH:mm:ss");
String time= "1970-01-06 11:45:55";//Note: Before and after the correction, a space is also added to
date date = Format.parse (time);
System.out.print ("Format to Times:" +date.gettime ());
Run Result:
Format to times:445555000
The gettime () in the date class in Java is getting the timestamp, the timestamp generated in Java is accurate to the millisecond level, and UNIX is accurate to the second level, so the timestamp generated through Java needs to be divided by 1000.
Two, the following is the Java code
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import java.util.Date;
public class Baidu {
/**
* @param args
*
/public static void main (string[] args) {
try {
String ti me = "2011/07/29 14:50:11";
Date date = new SimpleDateFormat ("Yyyy/mm/dd HH:mm:ss"). Parse (time);
Long Unixtimestamp = Date.gettime ()/1000;
System.out.println (Unixtimestamp);
} catch (ParseException e) {
e.printstacktrace ();}}}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.