java timestamp
package com.mkyong.date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TimeStampExample {
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
public static void main(String[] args) {
//method 1
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
System.out.println(timestamp);
//method 2 - via Date
Date date = new Date();
System.out.println(new Timestamp(date.getTime()));
//return number of milliseconds since January 1, 1970, 00:00:00 GMT
System.out.println(timestamp.getTime());
//format timestamp
System.out.println(sdf.format(timestamp));
}
}
CopyTimestamp timestamp = new Timestamp(System.currentTimeMillis());
//2016-11-16 06:43:19.77
Copy
Also in Java:
- how to use for loop for array in java
- connecting to h2 database from java
- how to create gravity in java
- make a commet in java
- java regex replace all characters before
- java
- how to do for each in java
- java bucket sort
- java file download
- how to detect if someone clicks on a jpanel in java
- java merge sort
- how to get witdth of window android
- official java website
- java prev permutation
- how to play an audio in java
- get first 5 characters of string java
- javafx textarea how to make smaller
- demo java file
- query java persistence
- check if string is null or empty java
- do while loop java
- how to check if a string is in alphabetical order in java
- java check if args is empty
- how to ask user for his location in android