Time formatting

I’m trying to get the time in the following format: hh:mm:ss. For example, 7:01:02 PM

If i use the following in a rule

and then store it in a variable using

{{$context.response.data.hh}}:{{$context.response.data.mm}}:{{$context.response.data.ss}} {{$context.response.data.A}}

why does the data appear as

7:1:2 PM, without the leading zeros. I’m most concerned about them in the minutes and seconds fields.

Using the http request in the browser gives me the correct data.

“timezone”: “Canada/Eastern”,
“locale”: “en”,
“iso”: “2022-10-18T19:01:02-04:00”,
“utc”: “2022-10-18T23:01:02+00:00”,
“unix”: 1666134062,
“millis”: 1666134062798,
“daysInMonth”: 31,
“YY”: “22”,
“YYYY”: “2022”,
“M”: “10”,
“MM”: “10”,
“MMM”: “Oct”,
“MMMM”: “October”,
“D”: “18”,
“DD”: “18”,
“d”: “2”,
“dd”: “Tu”,
“ddd”: “Tue”,
“dddd”: “Tuesday”,
“H”: “19”,
“HH”: “19”,
“h”: “7”,
“hh”: “07”,
“m”: “1”,
“mm”: “01”,
“s”: “2”,
“ss”: “02”,
“SSS”: “798”,
“Z”: “-04:00”,
“ZZ”: “-0400”,
“A”: “PM”,
“a”: “pm”,
“w”: “43”,
“W”: “42”

Numeric strings are implicitly parsed as numbers.

At this point, I would recommend using the native Expression feature if you have access to it (PM Sent). You could format the current time using the expression:

formatDate(now(), 'hh:mm:ss A')

If you prefer to continue using the /date Labs endpoint, I would suggest passing in the format parameter like so:


You could then grab the formatted property off the response which includes the fully formatted string:

  "timezone": "Canada/Eastern",
  "locale": "en",
  "iso": "2022-10-18T19:36:48-04:00",
  "utc": "2022-10-18T23:36:48+00:00",
  "unix": 1666136208,
  "millis": 1666136208116,
  "daysInMonth": 31,
  "YY": "22",
  "YYYY": "2022",
  "M": "10",
  "MM": "10",
  "MMM": "Oct",
  "MMMM": "October",
  "D": "18",
  "DD": "18",
  "d": "2",
  "dd": "Tu",
  "ddd": "Tue",
  "dddd": "Tuesday",
  "H": "19",
  "HH": "19",
  "h": "7",
  "hh": "07",
  "m": "36",
  "mm": "36",
  "s": "48",
  "ss": "48",
  "SSS": "116",
  "Z": "-04:00",
  "ZZ": "-0400",
  "A": "PM",
  "a": "pm",
  "w": "43",
  "W": "42",
  "formatted": "07:36:48 PM"

The variable would be:

$context.response.data.formatted //07:36:48 PM