Class Go
Time
class Time {
- public function __construct();
- public function add(int $d): Time;
- public function add_date(int $years, int $months, int $days): Time;
- public function after(object $u): bool;
- public function append_binary(string $b): string;
- public function append_format(string $b, string $layout): string;
- public function append_text(string $b): string;
- public function before(object $u): bool;
- public function clock(): array;
- public function compare(object $u): int;
- public function date(): array;
- public function day(): int;
- public function equal(object $u): bool;
- public function format(string $layout): string;
- public function gob_encode(): string;
- public function hour(): int;
- public function in(object $loc): Time;
- public function is_dst(): bool;
- public function is_zero(): bool;
- public function iso_week(): array;
- public function local(): Time;
- public function location(): Time\Location;
- public function marshal_binary(): string;
- public function marshal_text(): string;
- public function minute(): int;
- public function month(): int;
- public function nanosecond(): int;
- public function round(int $d): Time;
- public function second(): int;
- public function sub(object $u): Time\Duration;
- public function truncate(int $d): Time;
- public function unix(): int;
- public function unix_micro(): int;
- public function unix_milli(): int;
- public function unix_nano(): int;
- public function utc(): Time;
- public function weekday(): int;
- public function year(): int;
- public function year_day(): int;
- public function zone(): array;
- public function zone_bounds(): array;
}
Description
Time constructs the current instant in the runtime's default location.
Time is a class phpscript declares.
$object = new Time();
Methods
public function add(int $d): Time-
add returns the time t+d.
The go method
Add. public function add_date(int $years, int $months, int $days): Time-
add_date returns the time corresponding to adding the given number of years, months, and days to t. For example, AddDate(-1, 2, 3) applied to January 1, 2011 returns March 4, 2010.
Note that dates are fundamentally coupled to timezones, and calendrical periods like days don't have fixed durations. AddDate uses the Location of the Time value to determine these durations. That means that the same AddDate arguments can produce a different shift in absolute time depending on the base Time value and its Location. For example, AddDate(0, 0, 1) applied to 12:00 on March 27 always returns 12:00 on March 28. At some locations and in some years this is a 24 hour shift. In others it's a 23 hour shift due to daylight savings time transitions.
AddDate normalizes its result in the same way that Date does, so, for example, adding one month to October 31 yields December 1, the normalized form for November 31.
The go method
AddDate. public function after(object $u): bool-
after reports whether the time instant t is after u.
The go method
After. public function append_binary(string $b): string-
append_binary implements the [encoding.BinaryAppender] interface.
The go method
AppendBinary. public function append_format(string $b, string $layout): string-
append_format is like [Time.Format] but appends the textual representation to b and returns the extended buffer.
The go method
AppendFormat. public function append_text(string $b): string-
append_text implements the [encoding.TextAppender] interface. The time is formatted in RFC 3339 format with sub-second precision. If the timestamp cannot be represented as valid RFC 3339 (e.g., the year is out of range), then an error is returned.
The go method
AppendText. public function before(object $u): bool-
before reports whether the time instant t is before u.
The go method
Before. public function clock(): array-
clock returns the hour, minute, and second within the day specified by t.
The go method
Clock. public function compare(object $u): int-
compare compares the time instant t with u. If t is before u, it returns -1; if t is after u, it returns +1; if they're the same, it returns 0.
The go method
Compare. public function date(): array-
date returns the year, month, and day in which t occurs.
The go method
Date. public function day(): int-
day returns the day of the month specified by t.
The go method
Day. public function equal(object $u): bool-
equal reports whether t and u represent the same time instant. Two times can be equal even if they are in different locations. For example, 6:00 +0200 and 4:00 UTC are Equal. See the documentation on the Time type for the pitfalls of using == with Time values; most code should use Equal instead.
The go method
Equal. public function format(string $layout): string-
format returns a textual representation of the time value formatted according to the layout defined by the argument. See the documentation for the constant called [Layout] to see how to represent the layout format.
The executable example for [Time.Format] demonstrates the working of the layout string in detail and is a good reference.
The go method
Format. public function gob_encode(): string-
gob_encode implements the gob.GobEncoder interface.
The go method
GobEncode. public function hour(): int-
hour returns the hour within the day specified by t, in the range [0, 23].
The go method
Hour. public function in(object $loc): Time-
in returns a copy of t representing the same time instant, but with the copy's location information set to loc for display purposes.
In panics if loc is nil.
The go method
In. public function is_dst(): bool-
is_dst reports whether the time in the configured location is in Daylight Savings Time.
The go method
IsDST. public function is_zero(): bool-
is_zero reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC.
The go method
IsZero. public function iso_week(): array-
iso_week returns the ISO 8601 year and week number in which t occurs. Week ranges from 1 to 53. Jan 01 to Jan 03 of year n might belong to week 52 or 53 of year n-1, and Dec 29 to Dec 31 might belong to week 1 of year n+1.
The go method
ISOWeek. public function local(): Time-
local returns t with the location set to local time.
The go method
Local. public function location(): Time\Location-
location returns the time zone information associated with t.
The go method
Location. public function marshal_binary(): string-
marshal_binary implements the [encoding.BinaryMarshaler] interface.
The go method
MarshalBinary. public function marshal_text(): string-
marshal_text implements the [encoding.TextMarshaler] interface. The output matches that of calling the [Time.AppendText] method.
See [Time.AppendText] for more information.
The go method
MarshalText. public function minute(): int-
minute returns the minute offset within the hour specified by t, in the range [0, 59].
The go method
Minute. public function month(): int-
month returns the month of the year specified by t.
The go method
Month. public function nanosecond(): int-
nanosecond returns the nanosecond offset within the second specified by t, in the range [0, 999999999].
The go method
Nanosecond. public function round(int $d): Time-
round returns the result of rounding t to the nearest multiple of d (since the zero time). The rounding behavior for halfway values is to round up. If d <= 0, Round returns t stripped of any monotonic clock reading but otherwise unchanged.
Round operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Round(Hour) may return a time with a non-zero minute, depending on the time's Location.
The go method
Round. public function second(): int-
second returns the second offset within the minute specified by t, in the range [0, 59].
The go method
Second. public function sub(object $u): Time\Duration-
sub returns the duration t-u. If the result exceeds the maximum (or minimum) value that can be stored in a [Duration], the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d).
The go method
Sub. public function truncate(int $d): Time-
truncate returns the result of rounding t down to a multiple of d (since the zero time). If d <= 0, Truncate returns t stripped of any monotonic clock reading but otherwise unchanged.
Truncate operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Truncate(Hour) may return a time with a non-zero minute, depending on the time's Location.
The go method
Truncate. public function unix(): int-
unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC. The result does not depend on the location associated with t. Unix-like operating systems often record time as a 32-bit count of seconds, but since the method here returns a 64-bit value it is valid for billions of years into the past or future.
The go method
Unix. public function unix_micro(): int-
unix_micro returns t as a Unix time, the number of microseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in microseconds cannot be represented by an int64 (a date before year -290307 or after year 294246). The result does not depend on the location associated with t.
The go method
UnixMicro. public function unix_milli(): int-
unix_milli returns t as a Unix time, the number of milliseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in milliseconds cannot be represented by an int64 (a date more than 292 million years before or after 1970). The result does not depend on the location associated with t.
The go method
UnixMilli. public function unix_nano(): int-
unix_nano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or after 2262). Note that this means the result of calling UnixNano on the zero Time is undefined. The result does not depend on the location associated with t.
The go method
UnixNano. public function utc(): Time-
utc returns t with the location set to UTC.
The go method
UTC. public function weekday(): int-
weekday returns the day of the week specified by t.
The go method
Weekday. public function year(): int-
year returns the year in which t occurs.
The go method
Year. public function year_day(): int-
year_day returns the day of the year specified by t, in the range [1,365] for non-leap years, and [1,366] in leap years.
The go method
YearDay. public function zone(): array-
zone computes the time zone in effect at time t, returning the abbreviated name of the zone (such as "CET") and its offset in seconds east of UTC.
The go method
Zone. public function zone_bounds(): array-
zone_bounds returns the bounds of the time zone in effect at time t. The zone begins at start and the next zone begins at end. If the zone begins at the beginning of time, start will be returned as a zero Time. If the zone goes on forever, end will be returned as a zero Time. The Location of the returned times will be the same as t.
The go method
ZoneBounds.
Binding
- The go type
time.Time. - Registered by the package
time. - Built on
time.Time. - Satisfies
encoding.TextMarshaler. - Satisfies
fmt.Stringer. - Satisfies
encoding/json/v2.Marshaler.