Here you can find the source of addSeconds(Date date, int seconds)
Parameter | Description |
---|---|
date | a date. |
seconds | a number of seconds to add. |
public static Date addSeconds(Date date, int seconds)
//package com.java2s; /*//w ww . jav a 2 s. c om * Copyright (c) 2015-2016 QuartzDesk.com. * Licensed under the MIT license (https://opensource.org/licenses/MIT). */ import java.util.Calendar; import java.util.Date; public class Main { /** * Creates a new date as a clone of the specified date and adds the specified number of * seconds to it. * * @param date a date. * @param seconds a number of seconds to add. * @return the new date. */ public static Date addSeconds(Date date, int seconds) { Date newDate = (Date) date.clone(); Calendar cal = Calendar.getInstance(); cal.setLenient(true); cal.setTime(newDate); cal.add(Calendar.SECOND, seconds); return cal.getTime(); } }