How to Convert the Time.now() Value in Seconds Only in Okta
Last Updated:
Overview
This article details the Okta expressions to convert theTime.now() value in seconds only.
Applies To
- Okta Expression Language(OEL)
- Okta Classic Engine
- Okta Identity Engine (OIE)
- Lifecycle Management
Solution
In order to convert the Time.now() value to calculate the time in seconds only, the following expression can be used:
Convert.toInt(String.substring(Time.now("EST", "YYYY-MM-dd HH:mm:ss"),11,13)) * 3600 +
Convert.toInt(String.substring(Time.now("EST", "YYYY-MM-dd HH:mm:ss"),14,16)) * 60 +
Convert.toInt(String.substring(Time.now("EST", "YYYY-MM-dd HH:mm:ss"),17,19))
A simpler way may be to convert into unix time format. The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC.
Time.fromIso8601ToUnix(Time.now("EST"))