1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
/* Create java Date from specific time example. This example shows how to create a java Date object for specific date and time. */ import java.util.Date; public class CreateDateFromSpecificTimeExample { public static void main(String[] args) { /* To create a Date object for sepefic date and time use Date(long date) constuctor where date is the number of milliseconds since January 1, 1970, 00:00:00 GMT. */ //date after one year of January 1, 1970, 00:00:00 GMT Date d = new Date(365L * 24L * 60L * 60L * 1000L); System.out.println(d); } } /* TYPICAL Output Would be Thu Jan 01 00:00:00 EST 1971 */ |
The time shown in the final comment is correct for GMT, but not EST. What you really will see on your console depends on what time zone you have your computers clock set to. For my CST location I got:
Thu Dec 31 18:00:00 CST 1970
because CST time figure is six hours behind GMT. You people on the east coast will see:
Thu Dec 31 19:00:00 EST 1970
which is -5 hours difference from GMT. It’s because even though we all share the same planet, we all want the Sun to rise in the same hour of “our” clock, no matter where we sleep 🙂