banner



How Change Time And Date On Everlast Tr2

Java Add/subtract years, months, days, hours, minutes, or seconds to a Date & Time

In this article, yous'll find several ways of adding or subtracting years, months, days, hours, minutes, or seconds to a Date in Java.

Add/Subtract years, months, days, hours, minutes, seconds to a Appointment using Calendar class

                                  import                  java.text.                                    SimpleDateFormat                  ;                  import                  coffee.util.                                    Calendar                  ;                  import                  java.util.                                    Date                  ;                  public                  class                  CalendarAddSubtractExample                  {                  public                  static                  void                  primary                  (                  Cord                  [                  ]                  args)                  {                  SimpleDateFormat                  dateFormat                  =                  new                  SimpleDateFormat                  (                  "yyyy-MM-dd HH:mm:ss"                  )                  ;                  Date                  date                  =                  new                  Appointment                  (                  )                  ;                  System                  .out.                  println                  (                  "Current Date "                  +                  dateFormat.                  format                  (engagement)                  )                  ;                  // Convert Date to Calendar                  Agenda                  c                  =                  Calendar                  .                  getInstance                  (                  )                  ;                  c.                  setTime                  (date)                  ;                  // Perform add-on/subtraction                  c.                  add                  (                  Calendar                  .Yr,                  2                  )                  ;                  c.                  add                  (                  Calendar                  .MONTH,                  1                  )                  ;                  c.                  add                  (                  Calendar                  .Date,                  -                  10                  )                  ;                  c.                  add                  (                  Calendar                  .60 minutes,                  -                  four                  )                  ;                  c.                  add                  (                  Calendar                  .Infinitesimal,                  xxx                  )                  ;                  c.                  add                  (                  Calendar                  .SECOND,                  fifty                  )                  ;                  // Convert calendar back to Engagement                  Date                  currentDatePlusOne                  =                  c.                  getTime                  (                  )                  ;                  Organization                  .out.                  println                  (                  "Updated Date "                  +                  dateFormat.                  format                  (currentDatePlusOne)                  )                  ;                  }                  }                              
                                  # Output                  Current Date                  2020-02-24                  19:35:00 Updated Date                  2022-03-14                  16:05:50              

Add/Subtract years, months, weeks, days, hours, minutes, seconds to LocalDateTime

                                  import                  coffee.time.                                    LocalDateTime                  ;                  import                  java.time.temporal.                                    ChronoUnit                  ;                  public                  class                  LocalDateTimeAddSubtractExample                  {                  public                  static                  void                  primary                  (                  String                  [                  ]                  args)                  {                  LocalDateTime                  dateTime                  =                  LocalDateTime                  .                  of                  (                  2020                  ,                  1                  ,                  26                  ,                  10                  ,                  30                  ,                  45                  )                  ;                  // Add together years, months, weeks, days, hours, minutes, seconds to LocalDateTime                  LocalDateTime                  newDateTime                  =                  dateTime.                  plusYears                  (                  iii                  )                  .                  plusMonths                  (                  1                  )                  .                  plusWeeks                  (                  4                  )                  .                  plusDays                  (                  2                  )                  .                  plusHours                  (                  2                  )                  ;                  Arrangement                  .out.                  println                  (newDateTime)                  ;                  // Subtract years, months, weeks, days, hours, minutes, seconds to LocalDateTime                  newDateTime                  =                  dateTime.                  minusYears                  (                  3                  )                  .                  minusMonths                  (                  1                  )                  .                  minusWeeks                  (                  4                  )                  .                  minusDays                  (                  2                  )                  .                  minusMinutes                  (                  xxx                  )                  ;                  Organisation                  .out.                  println                  (newDateTime)                  ;                  // Add/Subtract using the generic plus/minus method                  Arrangement                  .out.                  println                  (dateTime.                  plus                  (                  ii                  ,                  ChronoUnit                  .DAYS)                  )                  ;                  }                  }                              
                                  # Output                  2023-03-28T12:xxx:45                  2016-11-26T10:00:45                  2020-01-28T10:30:45              

Add/Subtract days, weeks, months, years to LocalDate

                                  import                  java.time.                                    LocalDate                  ;                  import                  coffee.time.temporal.                                    ChronoUnit                  ;                  public                  class                  LocalDateAddSubtractExample                  {                  public                  static                  void                  chief                  (                  Cord                  [                  ]                  args)                  {                  LocalDate                  appointment                  =                  LocalDate                  .                  of                  (                  2020                  ,                  one                  ,                  26                  )                  ;                  // Add years, months, weeks, days to LocalDate                  LocalDate                  newDate                  =                  engagement.                  plusYears                  (                  3                  )                  .                  plusMonths                  (                  i                  )                  .                  plusWeeks                  (                  4                  )                  .                  plusDays                  (                  ii                  )                  ;                  System                  .out.                  println                  (newDate)                  ;                  // Subtract years, months, weeks, days to LocalDate                  newDate                  =                  date.                  minusYears                  (                  3                  )                  .                  minusMonths                  (                  one                  )                  .                  minusWeeks                  (                  4                  )                  .                  minusDays                  (                  2                  )                  ;                  Organisation                  .out.                  println                  (newDate)                  ;                  // Add/Decrease using the generic plus/minus method                  System                  .out.                  println                  (date.                  plus                  (                  two                  ,                  ChronoUnit                  .DAYS)                  )                  ;                  }                  }                              
                                  2023-03-28                  2016-11-26                  2020-01-28              

Add together/Subtract hours, minutes, seconds to LocalTime

                                  import                  java.time.                                    LocalTime                  ;                  import                  java.time.temporal.                                    ChronoUnit                  ;                  public                  grade                  LocalTimeAddSubtractExample                  {                  public                  static                  void                  primary                  (                  String                  [                  ]                  args)                  {                  LocalTime                  time                  =                  LocalTime                  .                  of                  (                  11                  ,                  45                  ,                  twenty                  )                  ;                  // Add hours, minutes, or seconds                  LocalTime                  newTime                  =                  time.                  plusHours                  (                  2                  )                  .                  plusMinutes                  (                  30                  )                  .                  plusSeconds                  (                  80                  )                  ;                  System                  .out.                  println                  (newTime)                  ;                  // Subtract hours, minutes, or seconds                  LocalTime                  updatedTime                  =                  fourth dimension.                  minusHours                  (                  ii                  )                  .                  minusMinutes                  (                  xxx                  )                  .                  minusSeconds                  (                  thirty                  )                  ;                  Organisation                  .out.                  println                  (updatedTime)                  ;                  // Add together/Subtract using the generic plus/minus method                  Arrangement                  .out.                  println                  (time.                  plus                  (                  1                  ,                  ChronoUnit                  .HOURS)                  )                  ;                  }                  }                              
                                  # Output                  14:16:twoscore 09:xiv:50                  12:45:20              

Source: https://www.callicoder.com/how-to-add-subtract-days-hours-minutes-seconds-to-date-java/

Posted by: hancockhitylo.blogspot.com

0 Response to "How Change Time And Date On Everlast Tr2"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel