i have trouble to manage time format between angularjs(javascript) - php - mysql . I stored time like 24:00:00, 12:00:00,01:30:00,05:34:00 from angular to mysql via php. Here i m using mysql's time type. While receiving the time via php from mysql's i got as string , but javascript ill understand date object then only i can able to show as time to views . Is any idea to handle this situation? I am used some time picker but those are not make my result better , I added the list of used plugins , please refer and also you my guide me to handle this .
here this author used as directive but i ill initialize model with above mentioned time format , i get invalidate date as result in console while pick the date , after submission the nulled value only passed as model value to server.
Sometimes is easier to work with Date.prototype.getTime()
var birthday = new Date(1994, 12, 10);
var time = birthday.getTime(); // 789696000000
var date2 = new Date(time); // Same as birthday
Then in the back end you can transform it into date with a simple helper. I have some C# (Migrate it to PHP or should be easy) code that do the job:
public class JsDateHelper : IJsDateHelper
{
public DateTime FromUnixTime(double unixTime)
{
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return epoch.AddMilliseconds(unixTime);
}
public long ToUnixTime(DateTime date)
{
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return Convert.ToInt64((date - epoch).TotalMilliseconds);
}
}
By doing it this way you will store in database the number 789696000000
and pass it to angular in angular you will transform it into an actual date using new Date(789696000000)
I think this way reduces complexity because you only have to worry about the format when you are going display the date.
Hope it helps!