Java String to Date toDate(String time)

Here you can find the source of toDate(String time)

Description

to Date

License

Apache License

Declaration

public static Date toDate(String time) 

Method Source Code


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

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

import java.util.TimeZone;

public class Main {
    public static Date toDate(String time) {
        if (time == null) {
            return null;
        }//from  w w w  .ja va  2 s . c om

        try {
            TimeZone tz = TimeZone.getTimeZone("UTC");
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS");
            df.setTimeZone(tz);
            return df.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String toDate(Date date) {
        DateFormat df = new SimpleDateFormat("dd/MM/yy");
        return df.format(date);
    }
}

Related

  1. toDate(String str)
  2. toDate(String strDate)
  3. toDate(String strDate)
  4. toDate(String string)
  5. toDate(String string, String format)
  6. toDate(String time)
  7. toDate(String ts)
  8. toDate(String value)
  9. toDateByFormat(String dateString, String formatStr)