Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Set the Date and Time with Gregorian Calendar in Java
To work with the GregorianCalendar class, import the following package.
import java.util.GregorianCalendar;
Create a Date object.
Date d = new Date();
Now, create an object and set the time using the setTime() method.
GregorianCalendar cal = new GregorianCalendar(); cal.setTime(d);
The following is an example.
Example
import java.util.Date;
import java.util.GregorianCalendar;
public class Demo {
public static void main(String[] a) {
Date d = new Date();
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(d);
System.out.println(d);
}
}
Output
Mon Nov 19 16:11:31 UTC 2018
Advertisements
