What is the method for obtaining the current timestamp in Java?
In Java, you can use the `System.currentTimeMillis()` method to obtain the current timestamp. This method returns the number of milliseconds since January 1, 1970, 00:00:00 GMT.
Here is an example code:
public class Main { public static void main(String[] args) { long timestamp = System.currentTimeMillis(); System.out.println("当前时间戳:" + timestamp); } }
The above code utilizes the `System.currentTimeMillis()` method to obtain the current timestamp and prints it to the console. Executing the code will output results similar to the following:
当前时间戳:1629889368558
The timestamp here indicates the number of milliseconds elapsed since January 1st, 1970 at 00:00:00 GMT.