Contact Free trial Login

now

now(): DateTime

Returns a DateTime value for the current date and time.

Example

This example uses now() to return the current date and time as a DateTime value. It also shows how to return a date and time in a specific time zone. Java 8 time zones are supported.

Source

%dw 2.0
output application/json
---
{
  nowCalled: now(),
  nowCalledSpecificTimeZone: now() >> "America/New_York"
}

Output

{
  "nowCalled": "2019-08-26T13:32:10.64-07:00",
  "nowCalledSpecificTimeZone": "2019-08-26T16:32:10.643-04:00"
}

Example

This example shows uses of the now() function with valid selectors. It also shows how to get the epoch time with now() as Number. For additional examples, see Date and Time (dw::Core Types).

Source

%dw 2.0
output application/json
---
{
  now: now(),
  epochTime : now() as Number,
  nanoseconds: now().nanoseconds,
  milliseconds: now().milliseconds,
  seconds: now().seconds,
  minutes: now().minutes,
  hour: now().hour,
  day: now().day,
  month: now().month,
  year: now().year,
  quarter: now().quarter,
  dayOfWeek: now().dayOfWeek,
  dayOfYear: now().dayOfYear,
  offsetSeconds: now().offsetSeconds,
  formattedDate: now() as String {format: "y-MM-dd"},
  formattedTime: now() as String {format: "hh:m:s"}
}

Output

{
  "now": "2019-06-18T16:54:29.379-07:00",
  "epochTime": 1560902069,
  "nanoseconds": 379000000,
  "milliseconds": 379,
  "seconds": 29,
  "minutes": 54,
  "hour": 16,
  "day": 18,
  "month": 6,
  "year": 2019,
  "quarter": 2,
  "dayOfWeek": 2,
  "dayOfYear": 169,
  "offsetSeconds": -25200,
  "formattedDate": "2019-06-18",
  "formattedTime": "04:54:29"
}

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.