getting rid of timestamp in returned string

Go To StackoverFlow.com

0

I want to get rid of the timestamp in this returned string. I am currently getting: "You have selected: Fri Sep 08 1978 00:00:00 GMT-0400 (EDT)"

The code is:

var chosenDates = $.datepicker.parseDate('yy-mm-dd', dateText);
$('.info').html('You have selected:' + '<br />' + chosenDates.toString());
2012-04-05 19:26
by amespower


1

You can specify the format in the toString method. For example:

var chosenDates = $.datepicker.parseDate('yy-mm-dd', dateText); 
$('.info').html('You have selected:' + '<br />' + chosenDates.toString('dd-MM-yyyy')); 

Edit: Or if you want to use the same format as in the date-picker: yy-mm-dd

Edit: You can also try with the formatDate function:

var chosenDates = $.datepicker.parseDate('yy-mm-dd', dateText); 
var backToString = $.datepicker.formatDate('yy-mm-dd', chosenDates);
$('.info').html('You have selected:' + '<br />' + backToString); 
2012-04-05 19:32
by aKzenT
I've tried that parameter and a bunch of others, but it's not working - amespower 2012-04-05 19:39
can you elaborate? do you get the exact same output regardless of what you specify for toString? Or is there another problem - aKzenT 2012-04-05 19:41
see the edit for an alternative solution - aKzenT 2012-04-05 19:45
yes, the same output every time, no matter what parameter I put in, including my own dateFormat like in your edit - amespower 2012-04-05 19:45
Perfect, thank you Akzen - amespower 2012-04-05 19:54
Ads