Skip to content

DateTime/DateTimeImmutable->getMicrosecond returns integer values, while leading zeroes matter #18219

@vuryss

Description

@vuryss

Description

The following code:

<?php

echo DateTime::createFromTimestamp(1743060675.001)->getMicrosecond()

Resulted in this output:

1000

But I expected this output instead:

001000

When we refer to any number that is supposed to be after the decimal point, leading zeroes matter. In this case because the method returns int, it strips any leading zeroes, making this method around 1 out of 10 times to return incorrect value.

PHP Version

8.4

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions