Reputation: 1890
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);
Please suggestion some better regex
Upvotes: 0
Views: 877
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