Advertisement



< Prev
Next >



Date Class





//Getting and Setting(modifying) the date

import java.util.*;

class A
{
public static void main(String... ar)
{
Date d1 = new Date();
System.out.println("Date1 : "+ d1);

Date d2 = new Date(1000000000l);
System.out.println("Date2 : "+ d2);


Date d3 = new Date(1000000000l);
System.out.println("Date3 : "+ d3);


System.out.println("Converting Date1 to Number of milliseconds since January 1, 1970 : " + d1.getTime());
System.out.println("Converting Date2 to Number of milliseconds since January 1, 1970 : " + d2.getTime());
System.out.println("Converting Date3 to Number of milliseconds since January 1, 1970 : " + d3.getTime());

d1.setTime(9999999999l);
d2.setTime(5000000000l);
d3.setTime(2222222222l);

System.out.println("Modified Date1 : "+ d1);
System.out.println("Modified Date2 : "+ d2);
System.out.println("Modified Date3 : "+ d3);
}
}


Output -


Date1 : Mon Jul 24 17:23:10 IST 2017
Date2 : Mon Jan 12 19:16:40 IST 1970
Date3 : Mon Jan 12 19:16:40 IST 1970
Converting Date1 to Number of milliseconds since January 1, 1970 : 1500897190947
Converting Date2 to Number of milliseconds since January 1, 1970 : 1000000000
Converting Date3 to Number of milliseconds since January 1, 1970 : 1000000000
Modified Date1 : Sun Apr 26 23:16:39 IST 1970
Modified Date2 : Sat Feb 28 02:23:20 IST 1970
Modified Date3 : Mon Jan 26 22:47:02 IST 1970


Program Analysis






Please share this article -




< Prev
Next >
< Java Scanner Class
Java Calendar Class>



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement

Notifications



Please check our latest addition

PYTHON and DJANGO


Advertisement