How to convert time in milliseconds to date time in Java

1 Answer

0 votes
package javaapplication1;

import java.util.Calendar;

public class JavaApplication1 {

    public static void main(String[] args) {

        Calendar cal = Calendar.getInstance();

        // Set time in milliseconds
        cal.setTimeInMillis(1476984263098L);

        System.out.print(cal.get(Calendar.YEAR) + "-");
        System.out.print(cal.get(Calendar.MONTH) + "-");
        System.out.print(cal.get(Calendar.DAY_OF_MONTH) + "  ");
        System.out.print(cal.get(Calendar.HOUR) + ":");
        System.out.print(cal.get(Calendar.MINUTE) + ":");
        System.out.println(cal.get(Calendar.SECOND));
    }
}

/*

run:

2016-9-20  8:24:23

*/

 



answered Oct 20, 2016 by avibootz

Related questions

1 answer 186 views
1 answer 158 views
2 answers 772 views
1 answer 132 views
...