I am using Laravel 5.7 and I am having a problem with the date string being passed from JS to PHP.
Before I passed the date in Vue JS and I put a console.log() to see the actual value and I have this:
Fri Feb 01 2019 00:00:00 GMT+0800 (Philippine Standard Time)
and then when I receive it to Laravel Controller, I \Log::info() to show the value being received but I have this:
2019-01-31T16:00:00.000Z
does anyone encountered the same problem and managed to fix it? Please help
It's not different date, just ISO formatted when you convert date into string.
you can create the date object again using new Date()
let date = new Date()
console.log(date)
console.log(date.toString())
let date2 = new Date(date.toString())
console.log(date2)
Related
I want to convert "22.11.2022 00:00:00" to Mon Nov 21 2022 00:00:00 GMT+0300 (GMT+03:00) and set picker value.
My code:
view.picker.setValue(this.jsonData.dateData)
I tried
console.log(Ext.Date.format(dt, 'l, \\t\\he jS \\of F Y h:i:s A')); // Wednesday, the 10th of January 2007 03:05:01 PM
but it didn't work.
How can I do this?
Because this question is related to ExtJS, i would suggest the following
Ext.Date.parse('22.11.2022 00:00:00', 'd.m.Y H:i:s')
docs:
https://docs.sencha.com/extjs/6.5.3/classic/Ext.Date.html
The main problem here is that the datepicker expects a JavaScript Date as it's value. You could easily achieve that by creating a new JavaScript Date using new Date(this.jsonData.dateData). Since you are getting a german Date/String represenation this would still not work.
If you change to the correct formatting you should get a valid Date Object that you can set to the picker.
const dateString = "22.11.2022 00:00:00",
dateObject = new Date(dateString.replace(/(.*)\.(.*)\.(.*)/, '$2-$1-$3'));
picker.setValue(dateObject);
Here is a working example: sencha fiddle
I would like to get a Date in the format below. I don't know the proper name (which has made searching quite difficult), but I call it a 'TZ string':
2016-01-28T20:39:17.512Z
I have tried:
> new Date("2016/02/28 00:19:58").toString()
'Sun Feb 28 2016 00:19:58 GMT+0000 (GMT)'
> new Date("2016/02/28 00:19:58").valueOf()
1456618798000
What's the proper name for a 'TZ string', and how can I turn a Date into one?
Got it, it's called an ISO 8601 date string:
new Date("2016/02/28 00:19:58").toISOString()
See date.toISOString() docs.
I have an element where the user is able to pick a date and time using this plugin:
https://github.com/xdan/datetimepicker/
I am using the following configuration options:
$('#startDate').datetimepicker({
format: 'Y-m-d\\TH:i:s',
});
The output:
$("#startDate").val()
returns:
"2016-02-18T23:59:00"
When I attempt to cast this string to the Date() object type like so:
Date("2016-02-18T23:59:00")
Date("2016-02-18T23:59:00Z")
Date("2016-02-18T23:59:00+00:00")
Date returns this (The current date/time):
"Wed Feb 17 2016 14:02:43 GMT-0600 (Central Standard Time)"
How do I get the datetimepicker to return a value that is recognized by the javascript Date() method, or how do I manually convert the returned date to a format recognized by the javascript Date() method?
try
var d = new Date("2016-02-18T23:59:00");
I am receiving times in the an AJAX request and am converting them using the new Date() function.
I receive 2013-06-18T12:00:15Z
However, somehow I get the following after new Date():
Tue Jun 18 2013 08:00:15 GMT-0400 (EDT)
Why is it not:
Tue Jun 18 2013 12:00
See the following demo:
http://www.w3schools.com/js/tryit.asp?filename=tryjs_date_convert
This is a time zone problem. You must be in the EDT timezone (GMT-0400). To correctly parse the date you should tell the parser in which timezone your date is correct.
For you parse your date like this :
new Date('2013-06-18 12:00:15 GMT-0400')
"GMT-0400" means GMT time minus 4 hours
Or if you don't wish to reformat your string, you can use the date.getUTC* functions to get the time as you parsed it.
The full list is available at Mozilla's documentation.
I agree with Vaim Caen's answer that this is a timezone issue, but not with parsing - the date is being parsed fine, but into your local timezone, while you're expecting it to be parsed into UTC date.
This answer shows how to convert from your current timezone to UTC - applying this to the TryIt demo gives:
var msec = Date.parse("2013-06-18T12:00:15Z");
// or: var msec = Date.parse("Tue Jun 18 2013 08:00:15 GMT-0400 (EDT)");
var d = new Date(msec);
d.setTime( d.getTime() + d.getTimezoneOffset()*60*1000 );
document.getElementById("demo").innerHTML = d;
Edit: If you all you're interested in is displaying the date (no further manipulations) then you can use:
d.toUTCString()
which will show the date in GMT (for me it actually shows "GMT" so most likely not of use!)
The alternative is to add a function to the prototype to show the date in whatever format you want and use the date.getUTC* methods.
Heres the code for converting the json retured date to a string of date.
String.toDate = function(stringDate) {
var newDate = new Date(parseInt(stringDate.replace("/Date(", "").replace(")/", ""), 10));
return newDate;
}
Here are the details:
Date from the database: 2009-11-18 03:23:25.107
Date Returned by JSON: "/Date(1258514605107)/"
Date Returned by the toDate function :
Wed Nov 18 2009 11:23:25 GMT+0800 (Taipei Standard Time)
Web Server and Database server time zone are the same.
Im wondering why the date becomes the current date in my timezone.
Is there anyone here encountered this kind of problem?
and what about your browser/OS settings ? you need the GMT time ?
I think you get get it with toUTCString a more complete reference about the date class
alert(newDate.toUTCString());