Hoverfly Cloud
Visit Our Main SitePricingTry Hoverfly Cloud
  • Introduction
  • Use cases for API Simulation
  • Key concepts
  • What's New
  • Dashboard
  • Simulation
    • Create simulations
    • Configuring Request Matchers
      • JSON Request Matchers on the Body
        • EXACT Matcher
        • JSON Matcher
        • JSON Partial Matcher
        • JSONPath Matcher
        • Regular Expression Matcher
      • Handling the response when Hoverfly cannot match
    • Building a JSON Response
      • Using a JSON object from the Request
      • Looping over a JSON array from the Request
    • Simulating Webhooks and Callbacks
    • Using templating in simulations
      • Render back any part of the Request
      • Render synthetic data
      • Faker functions
      • Render dates and times with offsets
      • Conditional logic
      • Looping over arrays
      • Variables and Arrays
      • Arithmetic operations
      • String operations
      • Validation operations
      • Simulating a persistent backend
      • Transitioning state between requests
      • Combining and nesting templating functions
      • Useful helper functions
      • Avoiding HTML encoding in function return values
    • Using data sources in simulations
      • Querying data sources
      • Updating data in data sources
      • Deleting data from data sources
      • Inserting data into a data source
      • Guidance on using the SQL like syntax
    • Working with Simulation Files
  • Service
    • Start a new service
    • Use a service
    • Update a service
    • Configuring Journal Indexing
  • Command line interface
    • Hoverfly Cloud CLI commands
  • Tutorials
    • Quickstart
    • Creating simulations and services
      • Tutorial 1: Create a service and simulation manually
      • Tutorial 2: Create a service and simulation by importing from a Swagger specification
      • Tutorial 3: Create a service and simulation by capturing real API traffic
    • Response Templating
      • Tutorial 4: Response Templating
    • Hoverfly service modes
      • Tutorial 5: Simulate, Capture, Spy and Passthrough modes
    • Automating with the CLI and API
      • Tutorial 6: Using the CLI and the Hoverfly Cloud API
Powered by GitBook
On this page
  1. Simulation
  2. Using templating in simulations

Render dates and times with offsets

The following date and time methods are supported:

Description

Example

Result

The current date time with offset, in the given format.

For example:

  • The current date time plus 1 day in unix timestamp

  • The current date time in ISO 8601 format

  • The current date time minus 1 day in custom format

  • {{ now '1d' 'unix' }}

  • {{ now '' '' }}

  • {{ now '-1d' '2006-Jan-02' }}

  • 1136300645

  • 2006-01-02T15:04:05Z

  • 2006-Jan-01

When using template helper method now, time offset must be formatted using the following syntax.

Shorthand

Type

ns

Nanosecond

us/µs

Microsecond

ms

Millisecond

s

Second

m

Minute

h

Hour

d

Day

y

Year

Prefix an offset with - to subtract the duration from the current date time.

Example time offset

5m

5 minutes

1h30m

1 hour 5 minutes

1y10d

1 year 10 days

Date time formats

Example date time formats

2006-01-02T15:04:05Z07:00

Mon, 02 Jan 2006 15:04:05 MST

Jan _2 15:04:05

PreviousFaker functionsNextConditional logic

Last updated 9 months ago

When using template helper method now, date time formats must follow the Golang syntax. More can be found out here

https://golang.org/pkg/time/#Parse