BST date string to javascript date -


how can convert bst date string javascript date object?

the follwing code gives me error bst works other timezone

var data='tue apr 28 16:15:22 bst 2015'; var date = new date(data); console.log(date) 

output

invalid date 

var data='tue apr 28 16:15:22 bst 2015';  var date = new date(data);  console.log(date)    var data2='fri mar 27 11:53:50 gmt 2015'  var date2 = new date(data2);  console.log(date2)

  1. don't rely on date know timezone names
  2. don't mix date time; year should before time, timezone should last thing

putting these together

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) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -