Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert string to Date object?

How to convert date string to Date object ?

2011-09-19T19:49:21+04:00
like image 381
Bdfy Avatar asked Oct 16 '11 14:10

Bdfy


People also ask

Can we convert string to Date?

SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy", Locale. ENGLISH); String dateInString = "7-Jun-2013"; Date date = formatter. parse(dateInString); In the above example, we first need to construct a SimpleDateFormat object by passing the pattern describing the date and time format.

How do you convert a string to a datetime object in Python?

To convert string to datetime in Python, use the strptime() method. The strptime() is a built-in function of the Python datetime class used to convert a string representation of the​ date/time to a date object.


2 Answers

Use jquery ui date parser.

http://docs.jquery.com/UI/Datepicker/parseDate

This is the best function for parsing dates out of strings that I've had the pleasure to work with in js. And as you added the tag jquery it's probably the best solution for you.

like image 185
fmsf Avatar answered Oct 04 '22 02:10

fmsf


The best way to do this is using new Date()

Example:

var stringDate = '2011-09-19T19:49:21+04:00'
var date = new Date(stringDate) // Mon Sep 19 2011 08:49:21 GMT-0700 (PDT)
like image 38
Verdi Erel Ergün Avatar answered Oct 04 '22 04:10

Verdi Erel Ergün