Java Hour Calculate addHour(String now)

Here you can find the source of addHour(String now)

Description

add Hour

License

Apache License

Declaration

public static String addHour(String now) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static String addHour(String now) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");

        Date dt;/*from ww  w. j  a v  a 2s .  co m*/
        try {
            dt = format.parse(now);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dt);

            calendar.add(Calendar.HOUR, 1);

            return format.format(calendar.getTime());

        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "";
        }

    }
}

Related

  1. addHours(int date, int hours)
  2. addNHours(Date date, int hours)
  3. diffHour(String day1, String day2)
  4. getBothTime(String startTime, int hours)