Java Hour Format formatDateTimeForSolr(Date d)

Here you can find the source of formatDateTimeForSolr(Date d)

Description

format Date Time For Solr

License

Open Source License

Declaration

public static String formatDateTimeForSolr(Date d) 

Method Source Code


//package com.java2s;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static final String DATE_PATTERN = "yyyy-MM-dd";
    public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final String DATETIME_PATTERN_SOLR = "yyyy-MM-dd'T'HH:mm:ss'Z'";

    public static String formatDateTimeForSolr(Date d) {
        return formatDateTime(d, DATETIME_PATTERN_SOLR);
    }//from   w  ww. j  a v a  2 s .  co  m

    public static String formatDateTimeForSolr(String d) {
        return formatDateTime(parseDate(d), DATETIME_PATTERN_SOLR);
    }

    public static String formatDateTime(Date d) {
        return formatDateTime(d, DATETIME_PATTERN);
    }

    public static String formatDateTime(Date d, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(d);
    }

    public static Date parseDate(String str) {
        return parseDateTime(str, DATE_PATTERN);
    }

    public static Date parseDateTime(String str) {
        return parseDateTime(str, DATETIME_PATTERN);
    }

    public static Date parseDateTime(String str, String pattern) {
        Date d = null;
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        try {
            d = sdf.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return d;
    }
}

Related

  1. FormatDateTime(String dateString)
  2. formatDateTime(String dateTime)
  3. formatDateTime(String strDateTime, String strFormat)
  4. formatDateTime12(String dateStr)
  5. formatDateTime24()
  6. formatDateTimeFull(Date dateTime)
  7. formatDateTimeStringForEquivalentCommand(final Date date)
  8. formatDateToEndDateTime(String strDate)
  9. formatDateToHMSString(java.util.Date date)