1

I'm working with an API that need the time with this format: "currentTime": 1534431933321 - unit is in MS.

How can I create that in Laravel using carbon?

And how to set my host time with getting that from endpoint?

RG Servers
  • 1,726
  • 2
  • 11
  • 27
aref razavi
  • 413
  • 2
  • 12

1 Answers1

1

What you are looking for is called "UNIX Time", can accomplish this with Carbon:

//$nowInMs: returns 1534431933321
$nowInMs = now()->getTimeStampMs();  

//$letsParseValue: returns 1674799200000
$letsParseValue = \Carbon\Carbon::parse('2023-01-27 10:00:00')->getTimeStampMs(); 

For reference on other getters use: https://carbon.nesbot.com/docs/#api-getters

To verify the times use this website: https://currentmillis.com/

RG Servers
  • 1,726
  • 2
  • 11
  • 27