Conversion Unixtime to another format

Asked

Viewed 41 times

-1

I have the following code PHP:

1 $timestamp = $stuMessage->unixTime;
2 fwrite($fh, "timestamp: ".$timestamp."\r\n");
3 $data = gmdate("Y-m-d", $timestamp);
4 $data2 = gmdate("Y-m-d", 1541421652);
5 fwrite($fh, $data. "\r\n");
6 fwrite($fh, $data2. "\r\n");

On line 4 I have the normal date return passing that Unix value which is the same value being assigned to the $timestamp variable.

But on line 3 I get a blank return with nothing.

inserir a descrição da imagem aqui

  • 1

    As this unixTime value is generated, it may be coming as a string and the $timestamp parameter is not being accepted by the gmdate function().

1 answer

0


The unixTime value is coming as a string, and the $timestamp parameter is not accepted by the gmdate() function. Convert to number and pass as parameter to function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.