im stuck at a problem here im getting the date in the following format
Wed May 16 2012 10:22:39 GMT+0500
i have tried
.toString('dd-MM-yyy');
but to no avail how can i parse the given format into the required one.
im stuck at a problem here im getting the date in the following format
Wed May 16 2012 10:22:39 GMT+0500
i have tried
.toString('dd-MM-yyy');
but to no avail how can i parse the given format into the required one.
You can use jQuery Date Format, it's a separate plugin that allows you to format dates very easily.
<script>
$.format.date("Wed May 16 2012 10:22:39 GMT+0500", "dd-MM-yyyy");
</script>
function zeroPad(d) {
return d < 10 ? '0' + d : d;
}
var date = new Date('Wed May 16 2012 10:22:39 GMT+0500'),
d = zeroPad(date.getDate()),
m = zeroPad(date.getMonth()+1);
var output = d + '-' + m + '-' + date.getFullYear();
There's no built-in way in JS to do date formatting like that. You need read each item manually from the Date
object.
var today = new Date();
var day = today.getDate();
...
If have a lot of work requiring date manipulation I suggest you take a look at Sugar JS library.
If you happen to already be using jQuery UI's "datepicker", there's a utility function included - $.datepicker.formatdate()
- http://docs.jquery.com/UI/Datepicker/formatDate