0

I have a unix timestamp as follows: 1561420800 which results in Monday, June 24, 2019 8:00:00 PM.

What I want is to use the timestamp so i can recreate a new timestamp and obtain the month and year and then results in Monday, June 24, 2019 00:00:00 AM

You can see the hours, minutes, and seconds are all 00 and its in the AM

If its possible in the DateTime object id prefer that. I cannot find any examples on the api https://www.php.net/manual/en/datetime.modify.php

somejkuser
  • 8,856
  • 20
  • 64
  • 130
  • Is [this](https://stackoverflow.com/questions/7768716/set-time-in-php-to-000000) what you are after? – Nigel Ren Nov 25 '19 at 19:59
  • @NigelRen i need to use the previous timestamp and modify it to have `00:00:00` as the hours/minutes/seconds – somejkuser Nov 25 '19 at 20:00
  • 1
    Does `date("l, F j, Y 00:00:00 \A\M", 1561420800)` not work for you? You probably want to think about this a little more... why are you truncating the time? Do you really want to shift by a timezone and then get the date? – Alex Barker Nov 25 '19 at 20:03
  • the value `1561420800` corresponds to `'2019-06-25 00:00:00' UTC`, so the time zone offset is going to need to be set appropriately (to get an offset of `-4:00`) if we wan to get that represented as `'2019-06-24 20:00:00'` – spencer7593 Nov 25 '19 at 20:06

1 Answers1

0

Using DateTime you can do the following...

$timestamp = 1561420800;
$dt = new DateTime('@' . $timestamp);
$dt->settime(0,0,0);
print_r($dt);

which shows the time set as

DateTime Object
(
    [date] => 2019-06-25 00:00:00.000000
    [timezone_type] => 1
    [timezone] => +00:00
)
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55