0

I am in a confusing situation. I am working with an API which requires a UNIX timestamp based on eastern time. Its format is something like this Date(1496332800000) while the UNIX timestamp is something like 1496332800000. I am not sure how can I convert simple date like 2017-08-29 to a format like 1496332800000

And it expects eastern time instead of UTC time. I am not sure how can I convert this

Machavity
  • 30,841
  • 27
  • 92
  • 100
Cowgirl
  • 1,454
  • 5
  • 19
  • 40
  • The definition of UNIX timestamp is timezone independent and is always based on UTC. – DFriend Dec 29 '17 at 03:07
  • This is from the docs, not sure if I am understanding it correctly `In the v4.1 APIs, all timestamps are formatted in eastern time, even if the store is not located in eastern time. For example the format "/Date(1496332800000)/" represents Thursday, June 1, 2017 12:00:00 PM (noon) for all store locations in any timezone. The integer value is UNIX time in milliseconds, except using eastern time rather than UTC. ` – Cowgirl Dec 29 '17 at 04:25

2 Answers2

0

First, it's important to understand that timestamps do not have a time zone. A timestamp represents a specific moment in time; for example, I could say "what is the timestamp right now?" It is, at the very moment I typed this:

1514516921

It does not matter where in the world you are, or I am, or anyone reading this is. This timestamp represents the same moment in time for all of us. For me, in my time zone, it is 7:08pm because I live in the US Pacific time zone. For someone living in New York, this moment in time (timestamp) occurred at 10:08pm. For someone living in Europe, the time of day is very different. But for all of us, that timestamp represented the moment I typed on my keyboard.

So, if your question is

how do I convert a date to a unix timestamp

in php, you usually use strtotime http://php.net/manual/en/function.strtotime.php Some examples:

<?php
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";
?>
KayakinKoder
  • 3,243
  • 3
  • 23
  • 37
  • This is quote from the docs itself `In the v4.1 APIs, all timestamps are formatted in eastern time, even if the store is not located in eastern time. For example the format "/Date(1496332800000)/" represents Thursday, June 1, 2017 12:00:00 PM (noon) for all store locations in any timezone. The integer value is UNIX time in milliseconds, except using eastern time rather than UTC. ` – Cowgirl Dec 29 '17 at 04:24
  • 1
    @Cowgirl can you give me a link to the docs? Without more context that doesn't make much sense – KayakinKoder Dec 29 '17 at 04:36
0

what i understand is that you want to convert 2017-08-29 to 1503964800.

if above is the case then use carbon. following is code with its output

Code: Carbon::parse('2017-08-29')->timestamp; output: 1503964800