Contact Us 1-800-596-4880

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:55:46.678-07:00",
  "epochTime": 1560902146,
  "nanoseconds": 678000000,
  "milliseconds": 678,
  "seconds": 46,
  "minutes": 55,
  "hour": 16,
  "day": 18,
  "month": 6,
  "year": 2019,
  "quarter": 2,
  "dayOfWeek": 2,
  "dayOfYear": 169,
  "offsetSeconds": -25200,
  "formattedDate": "2019-06-18",
  "formattedTime": "04:55:46"
}