var time="<?php echo $row['time']; ?>"; var time=new Date(time); var hrs=time.getHours(); var min=time.getMinutes();
Please find if there is any error in this code.
Without more knowledge I can’t really give you an answer.
But its likely that you’re expecting a Date Object, when in reality your DB is returning something else.
(Maybe a string?, a number?)
Make sure what type of data is exactly storen in your “time” variable. Would be my suggestion because I dont see errors in the code. Must be the logic
Really hope this helped but more insight into what your DB is doing would help getting a clear answer 🙂
Good Luck !
You could find answers for this all over Stackoverflow or read the docs on the date object.
However, here is an answer you might like
var myMinutes = 1; // This represent 1 minute subtraction var myHours = 60; // This represent 60 minutes subtraction which is 1 hour var dateMSubObject= new Date(oldDateObject.getTime() - myMinutes*60000); //Substracting your minutes variable var dateHSubObject= new Date(oldDateObject.getTime() - myHours*60000); //Substracting your hours variable
To make it more managable you could do hours like this aswell for etc 24 hours
var myHours = 60*24; // This represent 24 hours subtraction
You could also make the above code a function which wil take paramters like units, type and from that return your desired result
The 60000 part is milliseconds and represents 1 minute.
And welcome to StackOverflow, if you take some time exploring the website you will quickly be able to find the most common questions usually followed by great answers 🙂
This did it for me:
let jsdate = new Date(unixtimestamp+1000);
example in use:
let a = new Date(); console.log("a ="+a) let stamp = a.getTime() console.log("stamp ="+stamp) // timestamp let newTimeObj = new Date(stamp*1000) console.log("newTimeObj :::::::"+newTimeObj)
You need to convert the UNIX Timestamp(in seconds) which is coming from your
PHP code to milliseconds, and then pass it as a parameter to a
You can same achieve in PHP also, there you need to convert UNIX Timestamp to H:M format, using the
date() function, where the first parameter will the format you wanted and the second will be your
Where h is hours, in 12-hours format
i is minutes
Read move about PHP’s
data() function Date function in php
var time="<?php echo date('h:i', $row['time']); ?>"; //Now Split the above string into array var timeArray = time.split(":"); var hours = timeArray; var minutes = timeArray;
For more detail see this answer Convert UNIX Timestamp