Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Convert String to datetime in android [closed]

Tags:

I trying to convert string to date. My String like 20130526160000 . i want date like dd MMM yyyy hh:mm

e.g.-26 May 2013 16:00

like image 547
Suraj Avatar asked May 23 '13 11:05

Suraj


People also ask

How do I convert a String to a Date in spark SQL?

PySpark SQL function provides to_date() function to convert String to Date fromat of a DataFrame column. Note that Spark Date Functions support all Java Date formats specified in DateTimeFormatter. to_date() – function is used to format string ( StringType ) to date ( DateType ) column.


2 Answers

You can use SimpleDateFormat for parsing String to Date.

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
try {
  Date d = sdf.parse("20130526160000");
} catch (ParseException ex) {
  Log.v("Exception", ex.getLocalizedMessage());
}

Now you can convert your Date object back to String in your required format as below.

sdf.applyPattern("dd MMM yyyy hh:mm");
System.out.println(sdf.format(d));
like image 56
Obl Tobl Avatar answered Sep 22 '22 16:09

Obl Tobl


You can use the following way.

String strDate = "2013-05-15T10:00:00-0700";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
Date date = dateFormat.parse(strDate);
System.out.println(date);

Output is : Wed May 15 10:00:00 IST 2013 I hope this will help you.

like image 41
Gunaseelan Avatar answered Sep 21 '22 16:09

Gunaseelan