2

I am using JQuerys datepicker to retrieve dates. I am getting a date in the following string format Fri May 01 10:24:33 BST 2015.

I know you can convert strings in Javascript like

new Date('2011-04-11')

or

new Date('2011-04-11T11:51:00')

Does anyone know how i can i can convert Fri May 01 10:24:33 BST 2015 format to a date in Javascript?

theBigOzzy
  • 77
  • 1
  • 1
  • 11

1 Answers1

1

You are looking for something like this (your date is in BST format): BST date to Javascript date

var timezone_map = {
    'BST': 'GMT+0100'
};

function re_order(str) {
    var re = /^(\w+) (\w+) (\d\d) (\d\d:\d\d:\d\d) (\w+) (\d\d\d\d)$/;
    return str.replace(re, function ($0, day, month, date, time, zone, year) {
        return day + ' ' + month + ' ' + date + ' ' + year + ' ' + time + ' ' + (timezone_map[zone] || zone);
    });
}

new Date(re_order('Tue Apr 28 16:15:22 BST 2015'));
// Tue Apr 28 2015 16:15:22 GMT+0100 (GMT Daylight Time)
Community
  • 1
  • 1
Mou
  • 2,027
  • 1
  • 18
  • 29