Available in all subroutines.
Converts a string to a time variable.
The following string formats are supported:
Mon, 02 Jan 2006 22:04:05 GMT, RFC 822 and RFC 1123
Monday, 02-Jan-06 22:04:05 GMT, RFC 850
Mon Jan 2 22:04:05 2006, ANSI-C asctime()
2006-01-02 22:04:05, an ISO 8601 subset
1136239445.00, seconds since the Unix Epoch
1136239445, seconds since the Unix Epoch
The only time zone supported is
If the string does not match one of those formats, then the fallback variable is returned instead. We recommend using a fallback that's meaningful for your particular Fastly service.
declare local var.string TIME;set var.string = std.time("Mon, 02 Jan 2006 22:04:05 GMT", std.integer2time(-1));# var.string is now "Mon, 02 Jan 2006 22:04:05 GMT"declare local var.integer TIME;set var.integer = std.time("1136239445", std.integer2time(-1));# var.integer is now "Mon, 02 Jan 2006 22:04:05 GMT"declare local var.invalid TIME;set var.invalid = std.time("Not a date", std.integer2time(-1));# var.invalid is now "datetime out of bounds"
Try it out
std.time is used in the following solution recipes. Recipes apply VCL to real-world use cases and can be deployed as-is, or adapted for your own service. See the full list of recipesfor more inspiration.
Click RUN on a sample below to provision a Fastly service, execute the code on Fastly, and see how the function behaves.
Format dates and times in a variety of ways.
User contributed notes
We welcome comments that add use cases, ideas, tips, and caveats. All comments will be moderated before publication. To post support questions, visit our support center and we'll find you the help you need.