Java Date Format convertDateToString(Date date, int addHours)

Here you can find the source of convertDateToString(Date date, int addHours)

Description

convert Date To String

License

Apache License

Declaration

public static String convertDateToString(Date date, int addHours) 

Method Source Code

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

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

public class Main {
    public static String convertDateToString(Date date, int addHours) {

        Calendar cal = Calendar.getInstance(); // creates calendar
        cal.setTime(date); // sets calendar time/date
        cal.add(Calendar.HOUR_OF_DAY, addHours); // adds one hour
        return convertDateToString(cal.getTime()); // returns new date object
    }/*from  w  w w .  j  a  v a2  s  .co m*/

    public static String convertDateToString(Date date) {
        DateFormat df = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
        String reportDate = df.format(date);
        return reportDate;
    }
}

Related

  1. convertDateToString(Date date)
  2. convertDateToString(Date date)
  3. convertDateToString(Date date)
  4. convertDateToString(Date date)
  5. convertDateToString(Date date, boolean millis)
  6. convertDateToString(Date date, String dateFormat)
  7. convertDateToString(Date date, String format)
  8. convertDateToString(Date date, String pattern)
  9. convertDateToString(Date date, String pattern)