Тёмный

Java 8 LocalDate Api_PART1 

KK JavaTutorials
Подписаться 51 тыс.
Просмотров 11 тыс.
50% 1

Опубликовано:

 

15 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 10   
@pspkfan5991
@pspkfan5991 4 года назад
Good explanation. Thanks.
@JohnWick-zc5li
@JohnWick-zc5li 7 лет назад
thanks nice video
@KKJavaTutorials
@KKJavaTutorials 7 лет назад
Many thanks for the lovely comment!!!
@infitium7246
@infitium7246 4 года назад
Beware that 03 is used instead of 3.
@JohnWick-zc5li
@JohnWick-zc5li 7 лет назад
how subtract x days from date object Date currenDate = new Date()
@KKJavaTutorials
@KKJavaTutorials 7 лет назад
Hi John, Find the below code which answer your question.Provided code is self explanatory.. If you have any more questions then let me know. ====================================================================================================== import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.temporal.ChronoUnit; import java.util.Date; public class Test { public static void main(String[] args) { //1.Converting java.util.Date to java.time.LocalDateTime Date currenDate = new Date(); System.out.println("CurrenDate:"+currenDate); LocalDateTime currentDateTime = LocalDateTime.ofInstant(currenDate.toInstant(), ZoneId.systemDefault()); System.out.println("CurrentDateTime:"+currentDateTime); //2.Subtract X days form LocalDateTime int SUBTRACT_XDAYS = 5; LocalDateTime subtarctDateTime = currentDateTime.minus(SUBTRACT_XDAYS, ChronoUnit.DAYS); System.out.println("SubtarctDateTime:"+subtarctDateTime); //3.new Converting java.time.LocalDateTime to java.util.Date Instant instant = subtarctDateTime.atZone(ZoneId.systemDefault()).toInstant(); Date subtractedDate = Date.from(instant); System.out.println("SubtractedDate:"+subtractedDate); } }
@JohnWick-zc5li
@JohnWick-zc5li 7 лет назад
Hi Kishan, Thanks ...but actually the return should be a number of days not date object something like this private static int getDayOfMonth(Date aDate) { Calendar cal = Calendar.getInstance(); cal.setTime(aDate); return cal.get(Calendar.DAY_OF_MONTH); } Date = March 31 2017 - 2 days or + 1 days = noOfDays 29 days noOfDays 32
@JohnWick-zc5li
@JohnWick-zc5li 7 лет назад
Calendar cal1 = Calendar.getInstance(); cal1.setTime(new Date()); int day2 = cal1.get(Calendar.DAY_OF_MONTH); System.out.println(day2);
@KKJavaTutorials
@KKJavaTutorials 7 лет назад
Hey John, If you watch my videos:-> Java 8 Period/Duration date/time APIsru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-nDWc0_a8S74.html ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-z5suHVtUUqo.html Then easily you can find date difference in days. Thanks Kishan
Далее
Java 8 LocalDate Api_PART2
14:23
Просмотров 5 тыс.
САМАЯ ТУПАЯ СМЕРТЬ / ЧЕРНЕЦ
1:04:43
Stream API in Java
26:04
Просмотров 338 тыс.
Set and HashSet in Java - Full Tutorial
20:43
Просмотров 223 тыс.
Go Pointers: When & How To Use Them Efficiently
14:09
Java Functional Programming | Full Course
2:22:15
Просмотров 573 тыс.
Dependency Injection, The Best Pattern
13:16
Просмотров 850 тыс.
САМАЯ ТУПАЯ СМЕРТЬ / ЧЕРНЕЦ
1:04:43