Learn DATES & TIMES with Java in 8 minutes! ๐Ÿ“† @BroCodez
Learn DATES & TIMES with Java in 8 minutes! ๐Ÿ“†  @BroCodez
Uploaded December 2024 | Updated September 2026, 2 weeks ago
#java #javatutorial #javacourse

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class Main {
public static void main(String[] args) {

// How to work with DATES & TIMES using Java
// (LocalDate, LocalTime, LocalDateTime, UTC timestamp)

// Current date
LocalDate date = LocalDate.now();
System.out.println(date);

// Current time
LocalTime time = LocalTime.now();
System.out.println(time);

// Current date and time
LocalDateTime dateTime = LocalDateTime.now();
System.out.println(dateTime);

// UTC timestamp
Instant instant = Instant.now();
System.out.println(instant);

// Custom format
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
String newDateTime = dateTime.format(formatter);
System.out.println(newDateTime);

// Comparing dates & times
LocalDateTime date1 = LocalDateTime.of(2024, 12, 25, 12, 0, 0); // CHRISTMAS
LocalDateTime date2 = LocalDateTime.of(2025, 1, 1, 0, 0, 0); // NEW YEARS DAY

if(date1.isBefore(date2)){
System.out.println(date1 + " is earlier than " + date2);
}
else if(date1.isAfter(date2)){
System.out.println(date1 + " is later than " + date2);
}
else if(date1.isEqual(date2)){
System.out.println(date1 + " is equal to " + date2);
}
}
}
Learn DATES & TIMES with Java in 8 minutes! ๐Ÿ“†Lets code a NUMBER GUESSING GAME in C! โ†•๏ธLearn Python generators in 8 minutes! ๐ŸšฐLearn Java inheritance in 9 minutes! ๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆStart using NumPy in 5 minutes! ๐Ÿ”ขYoull love Python data classes! ๐Ÿ“‹Code a rock paper scissors game with Java! ๐Ÿ—ฟLearn Java generics in 13 minutes! ๐Ÿ“ฆLets code a QUIZ GAME with C programming! ๐Ÿ’ฏMatplotlib scatter plots in 6 minutes! โœจPointers are easy! ๐Ÿ‘ˆLearn Java timertasks in 6 minutes! โฒ๏ธ
Bro Code |

Learn DATES & TIMES with Java in 8 minutes! ๐Ÿ“†

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER