Java Day of getIncrementDaysSecond(String strDate, int sec)

Here you can find the source of getIncrementDaysSecond(String strDate, int sec)

Description

get Increment Days Second

License

Open Source License

Declaration

public static Date getIncrementDaysSecond(String strDate, int sec) throws Exception 

Method Source Code


//package com.java2s;
/*//from  www.  j a v  a  2s.c o  m
 * @(#)DateUtil.java   1.0  2004/03/15
 *
 * Copyright 2001 - 2004 Bestech, Inc. All rights reserved.
 * This software is the proprietary information of Bestech, Inc.
 * Use is subject to license terms.
 */

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

public class Main {

    public static Date getIncrementDaysSecond(String strDate, int sec) throws Exception {

        SimpleDateFormat sdf = null;
        Calendar calendar = new GregorianCalendar();
        Date date = null;

        int year = 0;
        int month = 0;
        int day = 0;
        int hour = 0;
        int minute = 0;
        int second = 0;

        if (strDate.length() == 10) {
            sdf = new SimpleDateFormat("yyyyMMdd", java.util.Locale.KOREA);
        } else {
            sdf = new SimpleDateFormat("yyyyMMddHHmmss", java.util.Locale.KOREA);
        }

        try {
            Date tmpDate = sdf.parse(strDate);
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }

        try {

            year = Integer.parseInt(strDate.substring(0, 4));
            month = Integer.parseInt(strDate.substring(4, 6));
            day = Integer.parseInt(strDate.substring(6, 8));
            hour = Integer.parseInt(strDate.substring(8, 10));
            minute = Integer.parseInt(strDate.substring(10, 12));
            second = Integer.parseInt(strDate.substring(12, 14));

        } catch (Exception e) {

            hour = 0;
            minute = 0;
            second = 0;
            //   throw new Exception(e.getMessage()+"Here");   
        }

        calendar.set(year, month - 1, day, hour, minute, second + sec);

        try {
            date = calendar.getTime();
        } catch (Exception e) {
        }

        return date;
    }
}

Related

  1. getFirstDayOfQuarter(Date date)
  2. getFirstOfDay(Date date)
  3. getFirstTimeInDay(Date day)
  4. getFormattedNowDatePlusDays(int days, String dateFormat)
  5. getFullAge(Date birthday)
  6. getInsertDayDate(int days)
  7. getIntervalDate(String date, int intervalDays)
  8. getIntervalDays(Date fDate, Date oDate)
  9. getIntevalDays(String startDate, String endDate)