pypyr.steps.nowutc permalink

get current utc timestamp permalink

Writes the current UTC date & time to context nowUtc.

If you want local or wall time, check out pypyr.steps.now instead.

If you run this step as a simple step (with no input nowUtcIn formatting), the default datetime format is ISO8601. For example: YYYY-MM-DDTHH:MM:SS.ffffff+00:00

You can use explicit format strings to control the datetime representation. For a full list of available formatting codes, check python date & time formatting

- pypyr.steps.nowutc # this sets {nowUtc} to YYYY-MM-DDTHH:MM:SS.ffffff+00:00
- name: pypyr.steps.echo
  in:
    echoMe: 'utc timestamp in ISO8601 format: {nowUtc}'
- name: pypyr.steps.nowutc
  description: use a custom date format string instead of the default ISO8601
  in:
    nowUtcIn: '%A %Y %m/%d %H:%M in timezone %Z offset %z, localized to %x'
- name: pypyr.steps.echo
  in:
    echoMe: 'custom formatting was set in the previous step: {nowUtc}'

All inputs support substitutions.

See a worked example for pipeline with now utc timestamp.

multiple timestamps in same pipeline permalink

If you have a pipeline where you want to refresh the timestamp multiple times, while using the same formatting, you can save yourself some typing by using contextsetf to specify the formatting nowUtcIn context property.

- name: pypyr.steps.contextsetf
  comment: set datetime formatting string
           this will endure for the entire pipeline.
  in:
    contextSetf:
      nowUtcIn: '%A %Y %m/%d %H:%M in timezone %Z offset %z, localized to %x'
- pypyr.steps.nowutc # uses nowUtcIn formatting from step 1
- name: pypyr.steps.echo
  in:
    echoMe: 'timestamp in custom format: {nowUtc}'
- pypyr.steps.nowutc # still uses nowUtcIn formatting from step 1
- name: pypyr.steps.echo
  in:
    echoMe: 'Using the refreshed timestamp but still same format: {nowUtc}'

see also

last updated on .