Java Second addTimes(String dateTime, int second)

Here you can find the source of addTimes(String dateTime, int second)

Description

add Times

License

Open Source License

Declaration

public static String addTimes(String dateTime, int second) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Main {
    public static String addTimes(String dateTime, int second) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        java.util.Date date1 = null;
        try {/* w ww  . jav  a  2  s .c  om*/
            date1 = format.parse(dateTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long Time = (date1.getTime() / 1000) + second;
        date1.setTime(Time * 1000);
        String mydate1 = format.format(date1);
        return mydate1;
    }

    public static long getTime(String time) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return format.parse("1970-01-01 " + time).getTime() - format.parse("1970-01-01 00:00:00").getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }
}

Related

  1. addSecond(Date beginDate, int addcount)
  2. addSeconds(Date date, int m)
  3. advanceCurrentTimeSeconds()
  4. appendSeconds(StringBuilder time, long seconds)
  5. appendSecondsToEncodeOutput(StringBuilder sb, int sec, int fsec, int precision, boolean fillzeros)
  6. asStringInSeconds(long duration)