![]() ![]() In this article, We've seen various ways to add minutes to the date or current date-time. Java 8 added with 10 mins : Wed Apr 08 22:20: ("-") Ĭurrent Date and TIme : Wed Apr 08 22:10:Īfter adding targetTime : Wed Apr 08 22:15:Īfter adding 10 mins with Caleder add() method : Wed Apr 08 22:20: ("10 mins added : " + addedTime.toLocalDateTime()) atZone(ZoneId.of("Asia/Karachi")).plusMinutes(10) ZonedDateTime addedTime = LocalDateTime.parse(" 12:30".replace(" ", "T")) ("Java 8 added with 10 mins : " + added10Mins) LocalDateTime dateTime = LocalDateTime.now().plus(Duration.of(10, ChronoUnit.MINUTES)) ĭate added10Mins = om(dateTime.atZone(ZoneId.systemDefault()).toInstant()) ("After adding 10 mins with Caleder add() method : " + tenMinsFromNow) To see the timestamp in your time zone, you can invoke the atZone () method on an Instant object. ![]() The now () method returns an instance of Instant itself. Java get utc time code#("Current time now : " + currentTimeNow.getTime()) ĭate tenMinsFromNow = currentTimeNow.getTime() Quick explanation of the above code In the above example, the static method () makes a call to the System clock to get the current machine timestamp in UTC time. ("After adding targetTime : " + targetTime) Ĭalendar currentTimeNow = Calendar.getInstance() TargetTime = DateUtils.addMinutes(targetTime, addMinuteTime) // add minute ("After adding 10 mins : " + afterAdding10Mins) ĭate targetTime = Calendar.getInstance().getTime() Long timeInSecs = date.getTimeInMillis() ĭate afterAdding10Mins = new Date(timeInSecs + (10 * 60 * 1000)) ("Current Date and TIme : " + date.getTime()) ![]() Adding 10 mins using Date constructor. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |