Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-conversion Convert Milliseconds to Date

Related Tutorials


 
 

Share on Google+Share on Google+

Convert Milliseconds to Date

Advertisement
In this section, you will learn to convert a millisecond into a date.

Convert Milliseconds to Date

     

In this section, you will learn to convert a millisecond into a date. 

Description of program:

This program helps you in converting milliseconds into a date. It uses some java methods and APIs.  you need a millisecond that have to be converted. The taken milliseconds is passed in the Date() constructor. It is then passed through the format() method that invokes with SimpleDateFormat() and it provides the given format. 

 The code of the program is given below:

import java.util.*;
import java.text.*;
public class MillisecondToDate {
 public static void main(String[] args)throws Exception {
 long yourmilliseconds = 1119193190;
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
 
Date resultdate = new Date(yourmilliseconds);
System.out.println(sdf.format(resultdate));  
}    

The output of the program is given below:

C:\date>javac MillisecondToDate.java
C:\date>java MillisecondToDate
Jan 14,1970 04:23

Download this example. 

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 16, 2007

Related Tutorials

Discuss: Convert Milliseconds to Date   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com