In this section, you will see how to convert millisecond into date.
How to convert millisecond value into date.
In this section, you will see how to convert the millisecond value into date.
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 currentTimeMillis() is a method of java System class. It returns current time of system. The getInstance() method of Calendar class gets calendar with default time Zone, and after it we set this millisecond value in into calendar. It is then passed through the format() method that invokes with SimpleDateFormat and it provides the given format.
Code:
import java.text.SimpleDateFormat; import java.util.Calendar; public class MilliSecondToDate { public static void main(String[] args) { SimpleDateFormat dateCalendar = new SimpleDateFormat( "yyyy.MMMM.dd hh:mm aaa"); long miliSecond = System.currentTimeMillis(); Calendar date = Calendar.getInstance(); date.setTimeInMillis(miliSecond); System.out.println("Date in MilliSecon : " + miliSecond); System.out.println("Date in format : " + dateCalendar.format(date.getTime())); } }Output
Date in MilliSecon :1290594687125
Date in format :2010.November.24 04:01 PM |
[ 0 ] Comments