This question already has answers here:
How to get current time in milliseconds in PHP?
(16 answers)
Closed 23 days ago.
This post was edited and submitted for review 22 days ago and failed to reopen the post:
Original close reason(s) were not resolved
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?
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/
Related
This question already has answers here:
How to store a datetime in MySQL with timezone info
(7 answers)
Best practices with saving datetime & timezone info in database when data is dependant on datetime
(2 answers)
Closed 4 years ago.
I have read a lot of articles about best way to store user's datetime. Here is a good one. The article suggests to store datetime in two seperate column one is for UTC datetime and another is for local datetime and another column for the local timezone. If i understood correctly the local date time referred to the user's/client's date time and timezone. Now i know i can save the UTC date time using UTC_TIMESTAMP(). But how do i save the local datetime and timezone using php? I need a direction here.
Maybe this would be helpful for you
Possible duplicate get local user time instead of server
Moreover, you can fetch local date time using javascript ajax call to server.
This question already has answers here:
How can I get the user's local time instead of the server's time?
(6 answers)
Closed 4 years ago.
I am trying to get the time of the user and have been experimenting with timestamp but found it to display inaccurate time unless I set the timezone to that particular state but this method seems tedious for setting all the states in the world.. I have seen some website where they allow the user to select their GMT timezone.... how is this done in php?
var now = new Date();
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
The JavaScript Date object supports a number of UTC (universal)
methods, as well as local time methods. UTC, also known as Greenwich
Mean Time (GMT), refers to the time as set by the World Time Standard.
The local time is the time known to the computer where JavaScript is
executed. Invoking JavaScript Date as a function (i.e., without the
new operator) will return a string representing the current date and
time.
This question already has answers here:
PHP > Set Default Timezone
(2 answers)
Closed 5 years ago.
My question is pretty simple but I'm not sure how to do it.
Currently I have a script that loads time and account and etc and executes it in the database but this is what I'm using.
$time = time();
The issue here is that it's loading the time from their own computer which can easily be abused since my script only enables you to use it every x hour(s). So what I'd like to do is to set a default timezone that the script will use instead of loading the time from their own computer.
Thank you in advance.
I'd determine the time in the database. I don't know which DB you're using but in MySQL you can use NOW() as a default value and you don't need to worry about it in your script anymore.
You can use date_default_timezone_set method to set default timezone, see example below:
date_default_timezone_set('America/Los_Angeles');
This question already has answers here:
Can a PHP script be run regularly on a server without requests from a client?
(5 answers)
Closed 8 years ago.
I am wondering if the following can be accomplished with PHP. Lets say that you have simple scripts which only insert some records into database (lets say some reporting) e.g. money incomes/withdraws.
And every 13th day in a month, you have some regular payment for electricity, mortgage etc. Is it possible, that PHP on 13th day every month at 00:00:01 AM perform some insert action.
In addition, is it possible that this is performed without even logging/using the application (without user interaction)? Is there a way how ensure that such action will be definately performed only once a month?
Thank you
What you're looking for is a cron job.
They are independent of any programming language.
This can be accomplished using a cronjob. You can find more information about that here.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Datatype/structure to store timezones in MySQL
How to store users timezone in mysql?
I see two options -- an offset from UTC or GMT, or storing the time zone in a string like "Asia/Seoul". I get that the offset method doesn't account for time changes, so I won't use that, but for some reason it seemed a bit odd to store a user's time zone just typed out in English. Is there some other time zone format that I overlooked?
If you're going to use PHP then a timezone string like Asia/Seoul will be easier to work with especially when you're using the DateTime suite of classes (especially DateTimeZone).