2

I have date string like Fri, 15 Nov 2013 09:00:00 -0600 in JavaScript(sent by server PHP). I need to parse this and get the timezone offset '-0600'. Is there any easy way to get the timezone offset from this string?

Thanks

4
  • Do you have access to the PHP, it might be cleaner to do this on the server side. Not to mention PHP's time/date functions are a little more flexible IMO. Commented Apr 6, 2013 at 7:16
  • 1
    Have you tried using Date.parse() in conjunction with Date.getTimezoneOffset()?
    – Aiias
    Commented Apr 6, 2013 at 7:17
  • 2
    @DCoder getTimezoneOffset() returns the local offset on the specified date, not the offset from the string.
    – Barmar
    Commented Apr 6, 2013 at 7:24
  • @DavidHoude I have access to PHP, but I think I dont want get timezone offset of each event time and send to clinet seperately. Commented Apr 7, 2013 at 1:11

2 Answers 2

1
var str = "Fri, 15 Nov 2013 09:00:00 -0600"
var output = str.split(' ').pop();

Demo: http://jsfiddle.net/D7c28/

1
  • split didnt work directly in some cases, I am using like 'str.toString().split(' ').pop()'. Yet to test on all browsers. Commented Apr 7, 2013 at 1:10
0
var reg_exp = /(-|\+)\d{4}/,
    timezone_offset = reg_exp.match("Fri, 15 Nov 2013 09:00:00 -0600")[0];

Not the answer you're looking for? Browse other questions tagged or ask your own question.