date_create

date_create(?string $datetime = "now", ?DateTimeZone $timezone = null): DateTime|false

Creates a DateTime object (the functional twin of new DateTime; returns false instead of throwing on parse failure).

C C23

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

int main(void) {
    /* C has no date object: time_t + struct tm is the standard pair */
    time_t ts = 1700000000;
    struct tm *utc = gmtime(&ts); /* break the epoch into calendar fields */
    char buf[20];
    strftime(buf, sizeof buf, "%Y-%m-%d %H:%M:%S", utc);
    printf("%s\n", buf);
    return 0;
}
Output
2023-11-14 22:13:20

C++ C++26

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

int main() {
    // C++17 chrono lacks calendar types (C++20 adds them); borrow the C pair
    std::time_t ts = 1700000000;
    std::tm utc = *std::gmtime(&ts);
    std::cout << std::put_time(&utc, "%Y-%m-%d %H:%M:%S") << "\n";
    return 0;
}
Output
2023-11-14 22:13:20

C# v11.0.100

v11.0.100
// DateTime is the OOP date object: build from parts or from a timestamp
var d = new DateTime(2023, 11, 14, 22, 13, 20, DateTimeKind.Utc);
Console.WriteLine(d.ToString("yyyy-MM-dd HH:mm:ss"));
var d2 = DateTimeOffset.FromUnixTimeSeconds(1700000000).UtcDateTime;
Console.WriteLine(d2.ToString("yyyy-MM-dd HH:mm:ss"));
Output
2023-11-14 22:13:20
2023-11-14 22:13:20

Go v1.27.4

v1.27.4
package main

import (
	"fmt"
	"time"
)

func main() {
	t := time.Date(2023, 11, 14, 22, 13, 20, 0, time.UTC) // from parts
	fmt.Println(t.Format("2006-01-02 15:04:05"))
	t2 := time.Unix(1700000000, 0).UTC() // from a Unix timestamp
	fmt.Println(t2.Format("2006-01-02 15:04:05"))
}
Output
2023-11-14 22:13:20
2023-11-14 22:13:20

Java v27.0.1

v27.0.1
import java.time.Instant;
import java.time.LocalDateTime;

public class Main {
    public static void main(String[] args) {
        System.out.println(LocalDateTime.of(2023, 11, 14, 22, 13, 20)); // from parts
        System.out.println(Instant.ofEpochSecond(1700000000)); // from a Unix timestamp (UTC)
    }
}
Output
2023-11-14T22:13:20
2023-11-14T22:13:20Z

JavaScript v26.13.1

v26.13.1
// Date wraps an epoch millisecond; months are 0-based (10 = November)
const d = new Date(Date.UTC(2023, 10, 14, 22, 13, 20));
console.log(d.toISOString());
const d2 = new Date(1700000000 * 1000); // from a Unix timestamp
console.log(d2.toISOString());
Output
2023-11-14T22:13:20.000Z
2023-11-14T22:13:20.000Z

PHP v8.6.0

v8.6.0
$d = date_create('2023-11-14 22:13:20'); // OOP twin of new DateTime()
echo $d->format('Y-m-d H:i:s'), PHP_EOL;
$d2 = date_create('@1700000000'); // from a Unix timestamp (@ means UTC)
echo $d2->format('Y-m-d H:i:s'), PHP_EOL;
Output
2023-11-14 22:13:20
2023-11-14 22:13:20

Python v3.15.2

v3.15.2
from datetime import datetime, timezone

d = datetime(2023, 11, 14, 22, 13, 20)  # naive: carries no timezone
print(d.isoformat())
d2 = datetime.fromtimestamp(1700000000, tz=timezone.utc)  # from a Unix timestamp
print(d2.isoformat())
Output
2023-11-14T22:13:20
2023-11-14T22:13:20+00:00

Rust v1.99.1

v1.99.1
use chrono::NaiveDate;

fn main() {
    // chrono: NaiveDateTime has no timezone; build from parts
    let d = NaiveDate::from_ymd_opt(2023, 11, 14)
        .unwrap()
        .and_hms_opt(22, 13, 20)
        .unwrap();
    println!("{}", d.format("%Y-%m-%d %H:%M:%S"));
    let d2 = chrono::NaiveDateTime::from_timestamp_opt(1700000000, 0).unwrap(); // from a Unix timestamp
    println!("{}", d2.format("%Y-%m-%d %H:%M:%S"));
}
Output
2023-11-14 22:13:20
2023-11-14 22:13:20

TypeScript v26.13.1

v26.13.1
// Date wraps an epoch millisecond; months are 0-based (10 = November)
const d = new Date(Date.UTC(2023, 10, 14, 22, 13, 20));
console.log(d.toISOString());
const d2 = new Date(1700000000 * 1000); // from a Unix timestamp
console.log(d2.toISOString());
Output
2023-11-14T22:13:20.000Z
2023-11-14T22:13:20.000Z

Language differences

C: no date object — the idiom is the time_t (epoch seconds) + struct tm (calendar fields) POD pair (example); gmtime goes UTC and localtime goes local, both sharing a static buffer (not thread-safe; use the *_r variants in threads).

C++: C++17 chrono has time points but no calendar (the example borrows the C struct); C++20 finally adds year_month_day/hh_mm_ss and the timezone library — version-constrained code coexists with struct tm indefinitely.

C#: DateTime is the legacy mutable-era object (example); DateTimeKind (Unspecified/Local/UTC) is just a label without conversion — cross-timezone work belongs to DateTimeOffset (FromUnixTimeSeconds in line two of the example).

Go: time.Time embeds a timezone + nanoseconds + a monotonic reading (example); time.Date takes fields directly and time.Unix comes from a timestamp; the zero time.Time is year 1, not 1970 — test with IsZero().

Java: jsr310 (java.time) is immutable value objects (example) — LocalDateTime carries no zone, Instant is the UTC epoch, ZonedDateTime is the full model; the old Date/Calendar are mutable with 0-based months and are banned in new code.

JavaScript: Date is essentially "an epoch millisecond plus a pile of accessors" (per the example comment) — 0-based months/weekdays are the famous trap; string parsing is implementation-defined, so production code trusts only ISO 8601 or field-by-field construction.

PHP: date_create is the functional twin of new DateTime, differing only in failure mode — the constructor throws, date_create returns false (pair with DateTime::getLastErrors); the @timestamp prefix parses as UTC (example).

Python: datetime splits into naive/aware (example) — an object without tzinfo must not mix with timezone arithmetic; fromtimestamp converts to the local zone by default, so cross-platform determinism requires an explicit tz=timezone.utc.

Rust: std has no date types; chrono is the de facto standard (example) — NaiveDateTime (no zone) and DateTime<Tz> (zoned) are separate models, and constructors return Option forcing invalid dates (no Feb 30) to be handled.

TypeScript: same as JavaScript; the Temporal proposal fixes the 0-based and mutability design flaws — until it lands, wrap with date-fns/dayjs.