Posts

Showing posts with the label Timestamps

Java - How to get current timestamps

In this section, we will show you examples  to get the current date time or timestamp in Java. 1. Java Timestamp examples The below program uses  java.sql.Timestamp  to get the current timestamp and format the display with  SimpleDateFormat . import java.sql.Timestamp ; import java.text.SimpleDateFormat ; import java.util.Date ; public class Main { // 2023.01.23.00.40.49 private static final SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat( "yyyy.MM.dd.HH.mm.ss" ); // 2023-01-23T00:40:49.761+05:30 private static final SimpleDateFormat simpleDateFormat12 = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" ); // 2023-01-23 00:40:49 private static final SimpleDateFormat simpleDateFormat13 = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); public static void main ( String [] args) { // method 1 Timestamp timestamp = new Timestamp( System . currentTimeMillis ());