getdate / gmdate

getdate(?int $timestamp = null): array | gmdate(string $format, ?int $timestamp = null): string

A pairing of the structured date array and always-UTC formatting: getdate returns every field at once (seconds/minutes/hours/mday/wday/mon/year/yday/weekday/month, in local-time semantics), while gmdate formats in UTC regardless of the default timezone (date() follows the default timezone instead).

C C23

C23
#include <stdio.h>
#include <time.h>

int main(void) {
    /* gmtime(3): the whole field bundle in one struct; localtime(3) is its local twin */
    time_t ts = 1700000000;
    struct tm *g = gmtime(&ts);
    printf("%04d-%02d-%02d %02d:%02d:%02d\n",
        g->tm_year + 1900, g->tm_mon + 1, g->tm_mday, g->tm_hour, g->tm_min, g->tm_sec);
    printf("wday=%d yday=%d\n", g->tm_wday, g->tm_yday); // wday: Sunday is 0, yday: 0-based
    return 0;
}
Output
2023-11-14 22:13:20
wday=2 yday=317

C++ C++26

C++26
#include <ctime>
#include <iomanip>
#include <iostream>

int main() {
    std::time_t ts = 1700000000;
    std::tm *g = std::gmtime(&ts); // field bundle (wday/yday included), UTC
    std::cout << std::put_time(g, "%Y-%m-%d %H:%M:%S") << "\n";
    std::cout << "wday=" << g->tm_wday << " yday=" << g->tm_yday << "\n"; // Sunday is 0, yday 0-based
    return 0;
}
Output
2023-11-14 22:13:20
wday=2 yday=317

C# v11.0.100

v11.0.100
var u = DateTimeOffset.FromUnixTimeSeconds(1700000000).UtcDateTime;
Console.WriteLine(u.ToString("yyyy-MM-dd HH:mm:ss"));
Console.WriteLine($"{u.DayOfWeek} yday={u.DayOfYear} month={u.Month}"); // DayOfYear is 1-based
Output
2023-11-14 22:13:20
Tuesday yday=318 month=11

Go v1.27.4

v1.27.4
package main

import (
	"fmt"
	"time"
)

func main() {
	u := time.Unix(1700000000, 0).UTC()
	y, m, day := u.Date()
	hh, mm, ss := u.Clock()
	fmt.Printf("%04d-%02d-%02d %02d:%02d:%02d\n", y, int(m), day, hh, mm, ss)
	fmt.Printf("%s yday=%d weekday=%d\n", u.Weekday(), u.YearDay(), int(u.Weekday())) // Sunday is 0
}
Output
2023-11-14 22:13:20
Tuesday yday=318 weekday=2

Java v27.0.1

v27.0.1
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

public class Main {
    public static void main(String[] args) {
        ZonedDateTime u = Instant.ofEpochSecond(1700000000L).atZone(ZoneOffset.UTC);
        System.out.printf("%04d-%02d-%02d %02d:%02d:%02d%n",
            u.getYear(), u.getMonthValue(), u.getDayOfMonth(), u.getHour(), u.getMinute(), u.getSecond());
        System.out.println(u.getDayOfWeek() + " yday=" + u.getDayOfYear()); // DayOfYear is 1-based
    }
}
Output
2023-11-14 22:13:20
TUESDAY yday=318

JavaScript v26.13.1

v26.13.1
const d = new Date(1700000000 * 1000); // UTC accessor variants
const p = (n) => String(n).padStart(2, '0');
console.log(
  `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())} ${p(d.getUTCHours())}:${p(d.getUTCMinutes())}:${p(d.getUTCSeconds())}`
);
const wd = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const start = Date.UTC(d.getUTCFullYear(), 0, 1);
const yday = Math.floor((d.getTime() - start) / 86400000) + 1; // 1-based day of year
console.log(`${wd[d.getUTCDay()]} yday=${yday} wday=${d.getUTCDay()}`); // Sunday is 0
Output
2023-11-14 22:13:20
Tuesday yday=318 wday=2

PHP v8.6.0

v8.6.0
date_default_timezone_set('UTC');
$d = getdate(1700000000); // one call returns every field at once
echo "{$d['year']}-{$d['mon']}-{$d['mday']} {$d['hours']}:{$d['minutes']}:{$d['seconds']}", PHP_EOL;
echo $d['weekday'], ' yday=', $d['yday'], ' wday=', $d['wday'], PHP_EOL;
echo gmdate('Y-m-d H:i:s', 1700000000), ' (gmdate)', PHP_EOL; // gmdate is always UTC
date_default_timezone_set('Asia/Tokyo');
echo date('Y-m-d H:i:s', 1700000000), ' (date, Tokyo)', PHP_EOL; // date() follows the default tz
echo gmdate('Y-m-d H:i:s', 1700000000), ' (gmdate again)', PHP_EOL;
Output
2023-11-14 22:13:20
Tuesday yday=317 wday=2
2023-11-14 22:13:20 (gmdate)
2023-11-15 07:13:20 (date, Tokyo)
2023-11-14 22:13:20 (gmdate again)

Python v3.15.2

v3.15.2
import time

t = time.gmtime(1700000000)  # struct_time: the field bundle, UTC (localtime is the local twin)
print(time.strftime('%Y-%m-%d %H:%M:%S', t))
print(f"{time.strftime('%A', t)} wday={t.tm_wday} yday={t.tm_yday}")  # tm_wday: Monday is 0
Output
2023-11-14 22:13:20
Tuesday wday=1 yday=318

Rust v1.99.1

v1.99.1
use chrono::{DateTime, Datelike, TimeZone, Timelike, Utc};

fn main() {
    // field-by-field access; weekday/yday conventions differ per language (see notes)
    let u: DateTime<Utc> = Utc.timestamp_opt(1700000000, 0).single().unwrap();
    println!(
        "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
        u.year(),
        u.month(),
        u.day(),
        u.hour(),
        u.minute(),
        u.second()
    );
    println!("{} wday={} yday={}", u.format("%A"), u.weekday().num_days_from_sunday(), u.ordinal() - 1);
}
Output
2023-11-14 22:13:20
Tuesday wday=2 yday=317

TypeScript v26.13.1

v26.13.1
const d: Date = new Date(1700000000 * 1000); // UTC accessor variants
const p = (n: number): string => String(n).padStart(2, '0');
console.log(
  `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())} ${p(d.getUTCHours())}:${p(d.getUTCMinutes())}:${p(d.getUTCSeconds())}`
);
const wd: string[] = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const start: number = Date.UTC(d.getUTCFullYear(), 0, 1);
const yday: number = Math.floor((d.getTime() - start) / 86400000) + 1; // 1-based day of year
console.log(`${wd[d.getUTCDay()]} yday=${yday} wday=${d.getUTCDay()}`); // Sunday is 0
Output
2023-11-14 22:13:20
Tuesday yday=318 wday=2

Language differences

C: gmtime(3) breaks out every field in one struct (struct tm includes wday/yday, example), with localtime(3) as its local-timezone twin — the counterpart of PHP's getdate; both share a static buffer, so use gmtime_r/localtime_r in threads; #include <time.h> is mandatory; always-UTC formatting is strftime over gmtime's result (the counterpart of gmdate).

C++: same as C — std::gmtime + std::put_time (example); C++20's std::chrono::year_month_day gives typed field access, but derived quantities like wday/yday still need std::chrono::weekday/sys_days hand-computation.

C#: fields are read one property at a time (Year/Month/Day/DayOfWeek/DayOfYear, example); DayOfYear is 1-based (one more than PHP's 0-based yday — measured 318 vs 317); prefer DateTimeOffset over bare DateTime to avoid timezone ambiguity.

Go: time.Time splits fields via Date()/Clock() (example); YearDay() is 1-based; Weekday() is Sunday=0, same convention as PHP; time.Now() is local — call .UTC() for UTC.

Java: jsr310 field access (example); getDayOfWeek() returns an all-caps enum and getDayOfYear() is 1-based (measured 318); Instant.atZone(ZoneOffset.UTC) is the UTC-determinism entry point.

JavaScript: the family of UTC accessors (getUTC*, zero-padding hand-rolled in the example); getUTCDay() is Sunday=0 like PHP; yday has no builtin — compute the offset from the year's start (example, 1-based); the same accessors without the UTC suffix use the local timezone.

PHP: getdate() returns every field in one call (seconds/minutes/hours/mday/wday/mon/year/yday/weekday/month plus element 0, the epoch — example's first two lines); it is local-timezone semantics, so pin date_default_timezone_set('UTC') to align with gmdate; gmdate() is always UTC and ignores the default timezone (the example's last three lines contrast Tokyo: date() shifts +9 while gmdate stays put); date() follows the default timezone like getdate.

Python: time.gmtime() is the UTC counterpart of getdate (a struct_time field bundle, example); time.localtime() is its local twin; note tm_wday is Monday=0 (unlike PHP's Sunday=0 — measured wday=1 vs PHP's 2) and tm_yday is 1-based.

Rust: chrono field access (example); weekday().num_days_from_sunday() aligns with PHP's wday convention (Sunday=0); ordinal()-1 converts to a 0-based yday; English weekday/month names come from format("%A"/"%B").

TypeScript: same getUTC* family as JavaScript; the "whole bundle at once" style can be composed from date-fns getDay/getYear, or awaited from Temporal's PlainDate direct field access.