Scripted dashboard convert time string to ms

Is there a inbuilt function in javascript library which will convert any time string specified in grafana to milliseconds… e.g a function which takes say “now-4d” and returns me corresponding epoch time in milliseconds(or seconds) as the case may be…Which i can then use to frame my own query in scripted dashboard.

Maybe use Date.Now() to do the conversion? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now

Yes, but i am thinking of some ready made function supplied by grafana which takes a string that could be wither ISO time or be in format of suhc as “now-4d” or “now + 3m” e.t.c and interpret the string and return the time value…Are you suggesting that i I roll down my own function which will parse a string and make successive appropriate calls to Date methods and then generate a value in ms and return…because It is exactly that i wanted to avoid … I wanted to use the same implementation that grafana used underneath to achieve because in that case i can afford to be consistent with grafana in terms of parsing the time fields in query params.


Date.parse is not able to interpret now+10h string and returns NaN