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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
/* Get current date time values using Java Calendar This example shows how to get current date and time values using Java Calendar class. */ import java.util.Calendar; public class GetCurrentDateTimeExample { public static void main(String[] args) { //get instance of Calendar class Calendar now = Calendar.getInstance(); /* * Calendar class has several contstants which represents current date * and time values */ //get current date, year and month System.out.println("Current Year is : " + now.get(Calendar.YEAR)); //month start from 0 to 11 System.out.println("Current Month is : " + (now.get(Calendar.MONTH) + 1 )); System.out.println("Current Date is : " + now.get(Calendar.DATE)); //get current time information System.out.println("Current Hour in 12 hour format is : " + now.get(Calendar.HOUR)); System.out.println("Current Hour in 24 hour format is : " + now.get(Calendar.HOUR_OF_DAY)); System.out.println("Current Minute is : " + now.get(Calendar.MINUTE)); System.out.println("Current Second is : " + now.get(Calendar.SECOND)); System.out.println("Current Millisecond is : " + now.get(Calendar.MILLISECOND)); //display full date time System.out.println("Current full date time is : " + (now.get(Calendar.MONTH) + 1) + "-" + now.get(Calendar.DATE) + "-" + now.get(Calendar.YEAR) + " " + now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND) + "." + now.get(Calendar.MILLISECOND) ); } } /* Typical output would be Current Year is : 2007 Current Month is : 12 Current Date is : 25 Current Hour in 12 hour format is : 6 Current Hour in 24 hour format is : 18 Current Minute is : 28 Current Second is : 54 Current Millisecond is : 797 Current full date time is : 12-25-2007 18:28:54.797 */ |
Does this read from the SYSTEM time, or the internet?
It will show your system time.