Tuesday 18 December 2018

How to format java.sql.Timestamp object | Java Date and Time


Click here to watch on Youtube: 
https://www.youtube.com/watch?v=eCuxuVKPDk4&list=UUhwKlOVR041tngjerWxVccw

TimestampDemo.java

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

public class TimestampDemo
{

    public static void main(String[] args)
    {

        long millis = System.currentTimeMillis();
        Timestamp timestamp = new Timestamp(millis);
        System.out.println(timestamp);

        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH.mm.ss");

        /*
         * Parameters:
         *
         * date - the time value to be formatted into a time string.
         *
         * Returns:
         *
         * the formatted time string.
         */

        String formatedStrDate = sdf.format(timestamp);
        System.out.println(formatedStrDate);

    }

}

Output

2018-11-07 09:38:42.398
07/11/2018 09.38.42

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/TimestampDemo_format.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/TimestampDemo_format

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/5bada39e8532ab4b75aaa28b80cdcee21bf19ab7/BasicJava_2018/TimestampDemo_format/?at=master

See also:

  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a Comment