Manoj
Manoj

Reputation: 1890

Abbreviated time zone regex

I need regex for taking abbreviated time zone in date object

Example: "Thu Oct 08 2015 20:03:40 GMT+0530 (India Standard Time)"

Expected:"Thu Oct 08 2015 20:03:40 GMT+0530 (IST)"

var str = new Date().toString().match(/\(([A-Za-z\s].*)\)/)[1] 
var newmsg = str.replace(/[a-z\s]/g, ''); 
console.log(newmsg);

Demo

Please suggestion some better regex

Upvotes: 0

Views: 877

Answers (1)

Chris Lear
Chris Lear

Reputation: 6742

Try this

console.log( new Date().toString().replace(/\(([A-Z]).*?\s([A-Z]).*?\s([A-Z]).*?\)/,'($1$2$3)'));

I'm assuming here that there are always 3 words, and they start with capital letters.

Upvotes: 1

Related Questions