Java在指定日期上加10秒

  • Post author:
  • Post category:java


package com.gang;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Harbor01 {
    public static void main(String[] args) throws InterruptedException, ParseException {


        SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
        String date = format.format(new Date());
        Calendar newTime = Calendar.getInstance();

        newTime.add(13,10);//日期加10秒
        Date dt1=newTime.getTime();

        System.out.println(date);
        String date2 = format.format(dt1);
        String date1 = format.format(new Date());
        System.out.println(date2);
        System.out.println(date1);


    }
}

=======================================================================

Code:

SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
Calendar newTime = Calendar.getInstance();
newTime.add(13,10);
Date dt1=newTime.getTime();
String date1 = format.format(new Date());
String date2 = format.format(dt1);
System.out.println(date1);
System.out.println(date2);



版权声明:本文为weixin_61503139原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。