date_default_timezone_set

date_default_timezone_set(string $timezoneId): bool

Sets the default timezone used by all date functions in the script.

C C23

C23
#include <stdio.h>
#include <time.h>
int main(void) {
    time_t t = 1700000000;
    struct tm *u = gmtime(&t); // UTC breakdown
    printf("%02d:%02d\n", u->tm_hour, u->tm_min);
    time_t c = t + 8 * 3600; // manual UTC+8 offset (no tz database in libc)
    struct tm *s = gmtime(&c);
    printf("%02d:%02d\n", s->tm_hour, s->tm_min);
    return 0;
}
Output
22:13
06:13

C++ C++26

C++26
#include <cstdio>
#include <ctime>
int main() {
    std::time_t t = 1700000000;
    std::tm *u = std::gmtime(&t); // UTC breakdown
    std::printf("%02d:%02d\n", u->tm_hour, u->tm_min);
    std::time_t c = t + 8 * 3600; // manual UTC+8 offset (no tz database in the stdlib)
    std::tm *s = std::gmtime(&c);
    std::printf("%02d:%02d\n", s->tm_hour, s->tm_min);
    return 0;
}
Output
22:13
06:13

C# v11.0.100

v11.0.100
var t = DateTimeOffset.FromUnixTimeSeconds(1700000000).ToUniversalTime();
Console.WriteLine(t.ToString("HH:mm", System.Globalization.CultureInfo.InvariantCulture));
var tz = TimeZoneInfo.FindSystemTimeZoneById("Asia/Shanghai"); // IANA id (cross-platform since .NET 6)
Console.WriteLine(TimeZoneInfo.ConvertTime(t, tz).ToString("HH:mm", System.Globalization.CultureInfo.InvariantCulture));
Output
22:13
06:13

Go v1.27.4

v1.27.4
package main

import (
    "fmt"
    "time"
)

func main() {
    cst := time.FixedZone("CST", 8*3600)
    fmt.Println(time.Unix(1700000000, 0).UTC().Format("15:04"))
    fmt.Println(time.Unix(1700000000, 0).In(cst).Format("15:04"))
}
Output
22:13
06:13

Java v27.0.1

v27.0.1
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

public class Main {
    public static void main(String[] args) {
        DateTimeFormatter f = DateTimeFormatter.ofPattern("HH:mm");
        Instant t = Instant.ofEpochSecond(1700000000);
        System.out.println(t.atZone(ZoneOffset.UTC).format(f));
        System.out.println(t.atZone(ZoneId.of("Asia/Shanghai")).format(f));
    }
}
Output
22:13
06:13

JavaScript v26.13.1

v26.13.1
const t = 1700000000000;
const fmt = (tz) => new Intl.DateTimeFormat("en-GB", { timeZone: tz, hour: "2-digit", minute: "2-digit", hour12: false }).format(t);
console.log(fmt("UTC"));
console.log(fmt("Asia/Shanghai"));
Output
22:13
06:13

PHP v8.6.0

v8.6.0
date_default_timezone_set("UTC");
echo date("H:i", 1700000000), "\n";
date_default_timezone_set("Asia/Shanghai");
echo date("H:i", 1700000000);
Output
22:13
06:13

Python v3.15.2

v3.15.2
import datetime
from zoneinfo import ZoneInfo

t = 1700000000
print(datetime.datetime.fromtimestamp(t, tz=ZoneInfo("UTC")).strftime("%H:%M"))
print(datetime.datetime.fromtimestamp(t, tz=ZoneInfo("Asia/Shanghai")).strftime("%H:%M"))
Output
22:13
06:13

Rust v1.99.1

v1.99.1
fn main() {
    // chrono has no tz database; use a fixed UTC+8 offset (Asia/Shanghai has no DST)
    let t = chrono::DateTime::from_timestamp(1700000000, 0).unwrap();
    let utc = t.with_timezone(&chrono::Utc);
    let cst = t.with_timezone(&chrono::FixedOffset::east_opt(8 * 3600).unwrap());
    println!("{}", utc.format("%H:%M"));
    println!("{}", cst.format("%H:%M"));
}
Output
22:13
06:13

TypeScript v26.13.1

v26.13.1
const t = 1700000000000;
const fmt = (tz: string): string =>
  new Intl.DateTimeFormat("en-GB", { timeZone: tz, hour: "2-digit", minute: "2-digit", hour12: false }).format(t);
console.log(fmt("UTC"));
console.log(fmt("Asia/Shanghai"));
Output
22:13
06:13

Language differences

C: the standard library has no timezone facility — either gmtime plus a manual offset, or localtime driven by the TZ environment variable.

C++: same as C — no timezone facility in the standard library.

C#: TimeZoneInfo.FindSystemTimeZoneById (IANA ids cross-platform since .NET 6).

Go: time.LoadLocation needs tzdata, so the example uses time.FixedZone instead.

Java: bundles its own tzdata (ZoneId.of works offline).

JavaScript: the timeZone option of Intl.DateTimeFormat (Node needs a full-ICU build).

PHP: the default timezone is process-wide global state affecting date(), strtotime(), and every other date function; after switching it, the same timestamp renders differently (from UTC 22:13 to UTC+8 06:13 in the example).

Python: other languages carry the zone on the object rather than in global state — 3.9+ zoneinfo.ZoneInfo (depends on system tzdata).

Rust: chrono has no tz database (IANA zones need the chrono-tz crate), so the example uses a fixed offset — safe for Asia/Shanghai since it has no DST.

TypeScript: same as JavaScript — the timeZone option of Intl.DateTimeFormat.