How to obtain the method instance of timestamp in Java
preface
Digital time stamp technology is a variant of digital signature technology. It refers to the total number of seconds from 00:00:00 GMT on January 1, 1970 (08:00:00 GMT on January 1, 1970) to the present (quoted from Baidu Encyclopedia)
In the process of java development, it is often encountered to count the data of a day or a month, Therefore, it is often necessary to obtain two timestamps of the intercepted data (for example, when counting today's data, it is necessary to obtain a start time of today's zero point and an end time of tomorrow's zero point), and then judge whether to include it in the statistical data according to whether the time related to the data is within this time interval.
1、 Java get timestamp
Not much to say. First, let's take the above example. How to obtain two time stamps of today's zero and tomorrow's zero.
The above method uses plusdays() in datetime. Similarly, if you need to obtain the timestamp before the next week (year, month, hour, minute, second, millisecond), there are the same plusyears (int x), plusmonths (int x) and so on. If you want to obtain the timestamp before today, you can pass in a negative integer parameter.
However, many times we need a time stamp of a specific time, such as the time stamp of 14:23:6.138 milliseconds on the 5th of this month (this time has no special meaning, it is optional).
For another example, we may need to know the time stamp of 10:10:10 on Tuesday.
2、 Two methods of obtaining time stamps accurate to seconds in Java
The milliseconds of timestamp in Java are mainly measured by the last three digits. Here are two different ways to remove the last three digits from the Internet.
Method 1: through string The substring () method removes the last three bits
Method 2: remove the last three digits by integer division
The above is my summary of some methods to obtain time stamps. If you need to quickly convert time and time stamps, you can also quickly solve it in the webmaster tool: Unix time stamps