Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery function to convert datetime, split date time "2010-10-18 10:06" to return "18/10/2010" and "10:06"

Hi I was wondering if there is any jquery function around which can take this dateTime "2010-10-18 10:06" and convert and split it returning "2010/10/18" and "10:06".

It would be also nice if the same function could either receive "2010-10-18 10:06" or "2010-10-18" only and return as mentioned above, or different formats besides "2010/10/18" like 18-10-2010" or and 18th of October 2010, giving the option but not that important, just curious about jQuery power dealing with dates.

Thanks.

like image 758
Amra Avatar asked Mar 08 '10 15:03

Amra


People also ask

How to split date time in jquery?

$('#date'). on('change', function() { var new_val = $(this). val(). split('-'), dateYear = parseInt(new_val[0]), dateMonth = parseInt(new_val[1]), dateDay = parseInt(new_val[2]); $('<input>', { type: 'hidden', name: 'date_day', id: 'date_day', value: dateDay }).

How can get current date in dd mm yyyy format in jquery?

You can do it like that: var d = new Date(); var month = d. getMonth()+1; var day = d. getDate(); var output = d.

What is T and Z in datetime Javascript?

In ISO 8601, T is a delimiter used for time, and Z is added to the end to indicate that the date has a zero UTC offset.


2 Answers

Converting with DateJs should be as easy as:

var d1 = Date.parse('2010-10-18, 10:06 AM');
alert(d1.toString('dd/mm/yyyy HH:mm:ss GMT'));

It's currently the best library around

like image 117
Marcos Placona Avatar answered Nov 11 '22 20:11

Marcos Placona


Without a any external jQuery plugin like DateJs. We can get the date as given below.

var datetime= '2010-10-18 10:06 AM' // Default datetime will be like this.

//By Spliting the input control value with space
var date=datetime.split(' ')[0];
//date -2010-10-18
like image 45
Henry Avatar answered Nov 11 '22 19:11

Henry