University of Engineering and Technology, Taxila
University of Engineering and Technology, Taxila
University of Engineering and Technology, Taxila
Technology ,Taxila
Assignment no 03
Class Description
Output:
Display Current Time
To display the current time (hour, minute, second, and nanoseconds), import the
java.time.LocalTime class, and use its now() method:
Example
import java.time.LocalTime; // import the LocalTime class
public class MyTime {
public static void main(String[] args) {
LocalTime myObj = LocalTime.now();
System.out.println(myObj);
}
}
Output:
To display the current date and time, import the java.time.LocalDateTime class, and use
its now() method:
Example:
import java.time.LocalDateTime; // import the LocalDateTime class
public class MyDateTime {
public static void main(String[] args) {
LocalDateTime myObj = LocalDateTime.now();
System.out.println(myObj);
}
}
Output:
Output:
The ofPattern() method accepts all sorts of values, if you want to display the date and time in
a different format. For example:
Value Example
yyyy-MM-dd "2020-11-14"
dd/MM/yyyy "14/11/2020"
dd-MMM-yyyy "14-Nov-2020"
OUTPUT:
OUTPUT: