Krishna Shetty
Krishna Shetty

Reputation: 1441

parse date string in JavaScript to get timezone offset

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

Upvotes: 2

Views: 1386

Answers (2)

hequ
hequ

Reputation: 771

var reg_exp = /(-|\+)\d{4}/,
    timezone_offset = reg_exp.match("Fri, 15 Nov 2013 09:00:00 -0600")[0];

Upvotes: 0

Eli
Eli

Reputation: 14827

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

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

Upvotes: 1

Related Questions