Hello,
I want to get the user’s login local time
I coded this script in javascript which is located an the header of every page which is visible to users
<script>
var currentTime = new Date();
// Get user current timestamp
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var year = currentTime.getFullYear();
var month = currentTime.getMonth() + 1;
var date = currentTime.getDate();
userCurrentTime = year+'-'+month+'-'+ date+' '+ hours+':'+minutes+':'+seconds;
console.log(userCurrentTime);
console.log() gives me the time stamp format that I want:
2024-2-17 1:41:8
Yet, when I convert the javascript variable to a PHP variable (so I can insert it itto a DB table)
$currenttime = "<script>document.write(currentTime);</script>";
I get a new date format
Sat Feb 17 2024 01:41:08 GMT+0200 (Israel Standard Time)
I don’t want to use a cookie because then I will need the users consent for cookies usage
Every thing I trued to do to change the format resulted in error messages, blank page, and the date 1970/1/1 00:00:00
What is the correct way to change the PHP date format to’Y-m-d H:m:i’ ?