I'm sending a json body from frontend to my backend, but the timestamp between frontend and backend are different. I'm using new Date().
Output Frontend: Wed Oct 07 2020 10:12:55 GMT+0200 (Central European Summer Time).
Output Backend: "timestamp":"2020-10-07T08:12:43.746Z"
I don't understand, why I get the timestamp wrong in my Backend. The Frontend is sending the correct time.
It is just different time Formating; Your Backend says Year-Month-Day Hours:Minutes:Seconds.Milisecconds
Your Frontend says Dayname Month Day Year Hours+2:Minutes:Secconds
Related
so I want to know that how can I convert firebase "timestamp" to only date and time... when I am using the toDate() method its showing me full output
OUTPUT:
Wed Jun 09 2021 23:32:02 GMT+0530 (India Standard Time)
and I want my output to be like this:
EXPECTED OUTPUT:
Wed Jun 09 2021 23:32:02
that's it !
how to convert it ?
Firestore sdk toDate() returns a javascript Date object. So you can format it the way you need from there. There are no other formatting options from the Firestore sdk.
There is more information on the Firestore Timestamp here: https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp
For formatting, one option (of many in JavaScript) is dateformat. It is much smaller than something like moment.js or dayjs and sufficient if all you are doing is formatting date/time output for display.
To format string for your desired output would be:
ddd mmm dd yyyy HH:MM:SS
I am using the DateTime-local in the HTML field to obtain the datetime from the users. I am sending the same to the backend which I am using to create the XML file. When I send the date to backend it subtracts itself by 2 hours for some reason.
I am not making any changes to it. I am currently in Central European Time (CET), I am guessing its changing automatically to UTC time because CET is 2 hours ahead of UTC. I am just curious to know whats happening here.
I am using the HTML, AngularJS and Nodejs for my project and following are my code samples:
HTML:
<input type="datetime-local" class="form-control" ng-model="formdata.EventTime">
For example, if I selected: 08 October 2020 12:30 PM then after the selection the field would appear something like this: 08/10/2020 12:30
In the AngularJS, just before making the HTTP POST request to my NODE.js I tried to console.log the time and it appeared something like this:
Thu Oct 08 2020 12:30:00 GMT+0200 (Central European Summer Time)
Now finally when I console.log in my Node.js then it appears something like this:
2020-10-08T10:30:00.000Z
I am just curious to know if this is some default functionality?
I could not find similar questions elsewhere so I am posting this.
There's a simple enough reason for the difference. The outputs of both are showing the same instant in time, however the AngularJS log is formatting the date in RFC 2822 format which shows the local timezone, while Node.js is logging the time in UTC formatted as an ISO 8601 time.
If you do this in both AngularJS and Node.js:
console.log(date.toISOString());
You'll get the same output (e.g.)
2020-10-08T10:30:00.000Z
Likewise if you try
console.log(date.toString());
You should get a similar output but in RFC 2822 format (e.g.)
Thu Oct 08 2020 12:30:00 GMT+0200 (Central European Summer Time)
Thanks, #Terry for the response. Based on his answer I did the following, I used the moment to convert my time from UTC to local. My project required me to retain the format of the date and syntax of it.
Install the moment library in Node.js.
When I was selecting 08/10/2020 15:30 in the datetime-local I was getting following date in Node.js:
2020-10-08T13:30:00.000Z
I tried converting it using:
EventTime = moment.utc(EventTime).local().format('YYYY-MM-DDTHH:mm:SS.sss');
Finally I got following output:
2020-10-08T15:30:00.000
I hope if someone else has the same doubt this might help.
I am using SOAP UI and submitting a JSON submission. However I am not sure how to submit so that the current date/time is automatically populated like for the JSON body field as below
"receivedDateTime":"2020-09-10T07:40:00.001Z"
I tried the following for a similar field as above
"preparationDateTime":"${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new java.util.Date())}", but I don't think it works
HEADER
I have been able to set up the current UTC format for one of the dates in the header but that's UTC format
${= new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ") }
but another date in the header date/time needs to be in RFC7231 format - Thu, 01 Oct 2020 13:30:23 GMT
so not sure how to do this?
Can anyone help please?
For RFC7231 format, you can use
"preparationDateTime":"${=new java.text.SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'").format(new java.util.Date())}"new SimpleDateFormat("").format(new Date())
Aforementioned date format will return "Thu, 19 Nov 2020 18:39:01 GMT"
I have a DATETIME field named "event_timestamp" in MySQL database that has the following value:
2014-07-23 12:31:00
When I query the database (I use SAILS, waterline ORM is used, specifically find() function), the result object shows the value shifted by "2 hours"
results.event_timestamp : Wed Jul 23 2014 14:31:00 GMT+0200 (EEST)
How can I handle this, I tried setting timezones in Mysql & Nodejs but to no avail.
It is not shifted by two hours, it is converted from a timestamp without a time zone to a timestamp with a time zone. When you store dates in a database, they are automatically saved in UTC time, so it is implied that your date
2014-07-23 12:31:00
is really
Wed Jul 23 2014 12:31:00 GMT+0000 (UTC)
When you query it using Waterline, it automatically gets converted to your local time zone format, giving you:
Wed Jul 23 2014 14:31:00 GMT+0200 (EEST)
I have a web page with a DatePicker control (from Kendo UI) on it.
Firstly, I'm in New Zealand, which is UTC +12:00
When I select a date of 31st October 2012 in my date picker, it gets stored in the JavaScript object as:
Wed Oct 31 00:00:00 UTC+1300 2012
This seems wrong!
It gets serialized to JSON (using JSON.stringify) as 2012-10-30T11:00:00.000Z, which is wrong.
Back on the server, when the JSON is parsed, this comes out at 30th October 2012, 23:00.
Can somebody explain this to me? And what is the solution?
I have this figured out now - the date picker control is working correctly, as for the date of October 31st, New Zealand will be in Daylight Savings Time, so at that date, we will be UTC +1300.
My problem is that my server code is converting to UTC on the basis of today's date, rather than using the offset as it would be on the the actual date.