Java String to Date toDateStyleBoth(String dateStr)

Here you can find the source of toDateStyleBoth(String dateStr)

Description

to Date Style Both

License

LGPL

Declaration

public static Date toDateStyleBoth(String dateStr) 

Method Source Code


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

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

import java.util.Date;

public class Main {
    public static Date toDateStyleBoth(String dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {/*  w  w  w .  j  a v  a  2 s.c  o m*/
            return sdf.parse(dateStr);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    public static String toDateStyleBoth(Date dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(dateStr);
    }
}

Related

  1. toDateString(java.util.Date date, String format)
  2. toDateString(java.util.Date date, String spe)
  3. toDateString(long lval)
  4. toDateString(long ms)
  5. toDateString(String fmt, Date date)
  6. toDatetime(String sDate)
  7. toDateTimeFormat(String input, String inputfmt, String outputfmt)
  8. toDateTimeSSSString(long datetime)
  9. toDateTimeString(java.util.Date date)