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()? Commented Apr 6, 2013 at 7:17
  • 2
    @DCoder getTimezoneOffset() returns the local offset on the specified date, not the offset from the string. 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/

Sign up to request clarification or add additional context in comments.

1 Comment

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.