regex - How to extract a date value from a string using regexp in javascript? -


i have string this:

var value = "/date(1454187600000+0300)/" - required date format 1/30/2016 - trying this:

var value = "/date(1454187600000+0300)/" // need fetch here. var nd = new date(1454187600000); //this static. var month = nd.getutcmonth() + 1; //months 1-12 var day = nd.getutcdate(); var year = nd.getutcfullyear(); newdate = month + "/" + day + "/" + year; console.log( newdate ); //works fine 

but don't know how fetch numbers value variable using regexp. 1 me?

you can use capture group extract date part you're looking for:

nd = new date(value.match(/\/date\((\d+)/)[1] * 1); //=> sat jan 30 2016 16:00:00 gmt-0500 (est) 

here /\/date\((\d+)/)[1] give "1454187600000" , * 1 convert text integer.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -