The Artima Developer Community
Sponsored Link

Java Buzz Forum
subtract minutes from date time in java

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
subtract minutes from date time in java Posted: Oct 19, 2017 1:32 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: subtract minutes from date time in java
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
  • We have discussed about how to subtract hours from java 8 using LoclaDateTime class in java.
  • How to subtract N hours from current date time using java 8
  • Now we will see how to subtract minutes from current date time in java.
  • How to subtract minutes from current time in java / How to subtract minutes from time in java.
  • Lets see an example java program which will subtract minutes from java date time



Program #1 : Java Example Program to subtract minutes from given string formatted date time using java 8.



  1. package java8;
  2. /**
  3.  * By: www.instanceofjava.com
  4.  * program: how to subtract minutes from date time using java 8  
  5. *
  6.  */
  7. import java.time.LocalDateTime;
  8. import java.time.format.DateTimeFormatter;
  9.  
  10. public class SubtractMinutesJava{

  11. public static void main(String[] args) {
  12.  
  13.   DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  14.  
  15.         String currentTime= "2017-10-19 22:00:00";

  16.  
  17.         System.out.println("Before subtraction of minutes from date: "+currentTime);
  18.  
  19.         LocalDateTime datetime = LocalDateTime.parse(currentTime,formatter);
  20.  
  21.         datetime=datetime.minusMinutes(30);
  22.  
  23.         String aftersubtraction=datetime.format(formatter);
  24.         System.out.println("After 30 minutes subtraction from date: "+aftersubtraction);

  25.  
  26.     }
  27.  
  28. }

Output:

  1. Before subtraction of minutes from date: 2017-10-19 22:00:00
  2. After 30 minutes subtraction from date: 2017-10-19 21:30:00


Program #2 : Java Example Program to subtract seconds from given string formatted date time using java 8.



  1. package java8;
  2. /**
  3.  * By: www.instanceofjava.com
  4.  * program: how to subtract hours from date time using java 8  
  5. *
  6.  */
  7. import java.time.LocalDateTime;
  8. import java.time.format.DateTimeFormatter;
  9.  
  10. public class SubtractSecondsJava{

  11. public static void main(String[] args) {
  12.  
  13.   DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  14.  
  15.         String currentTime= "2017-10-19 22:00:00";

  16.  
  17.         System.out.println("Before subtraction of seconds from date time: "+currentTime);
  18.  
  19.         LocalDateTime datetime = LocalDateTime.parse(currentTime,formatter);
  20.  
  21.         datetime=datetime.minusSeconds(30);
  22.  
  23.         String aftersubtraction=datetime.format(formatter);
  24.         System.out.println("After 30 seconds subtraction from date time: "+aftersubtraction);

  25.  
  26.     }
  27.  
  28. }

Output:

  1. Before subtraction of seconds from date time: 2017-10-19 22:00:00
  2. After 30 seconds subtraction from date time: 2017-10-19 21:59:30

Program #3 : Java Example Program to subtract seconds from current date time using java 8.



how to subtract minutes from java date time

Read: subtract minutes from date time in java

Topic: Creating Multi-Release JAR Files in IntelliJ IDEA Previous Topic   Next Topic Topic: How to subtract N hours from current date time using java 8

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use