Oihana PHP

now.php

Table of Contents

Functions

now()  : string
Returns the current date/time as a formatted string.

Functions

now()

Returns the current date/time as a formatted string.

now([string $timezone = 'UTC' ][, string|null $format = DateFormat::DEFAULT ]) : string

The $timezone parameter is used only to interpret the "now" value. Since the default format ends on a literal Z, the ISO-8601 designator for UTC, the result is converted to UTC whichever timezone is asked for — see formatDateTime() for the full rule.

Parameters
$timezone : string = 'UTC'

The timezone identifier (e.g., 'Europe/Paris'). Defaults to 'UTC'.

$format : string|null = DateFormat::DEFAULT

The date format string compatible with DateTime::format(). Defaults to DateFormat::DEFAULT (ISO 8601 UTC with milliseconds).

Tags
throws
DateInvalidTimeZoneException

If the provided timezone string is invalid.

DateMalformedStringException

If the date creation fails (should not occur with 'now').

example
echo now() ;
// Output: '2025-07-20T13:30:20.676Z'

echo now( 'Europe/Paris' ) ;
// Output: '2025-07-20T13:30:20.676Z' (the same moment — the default format is UTC)

echo now( 'Europe/Paris' , 'H:i' ) ;
// Output: '15:30' (no literal Z, so the Paris wall clock)
author

Marc Alcaraz (ekameleon)

since
1.0.0
Return values
string

The formatted current date/time string.

On this page

Search results