How to change date format in HTML5 - html

I need to display a date in HTML(application is using HTML5+Thymeleaf).
How to convert from the below format
Wed Jul 01 09:09:51 IST 2015
To
Wed Jul 01 2015 09:09:51 GMT+0530 (Indian Standard Time)
And also , if I give new Date() in controller class, its displaying(in log) as
Thu Jun 11 06:41:11 IST 2015
But if I give new Date() in HTML, it is displaying(in alert) in below format.
Thu Jun 11 2015 06:41:12 GMT +0530 (Indian Standard Time)
HTML Code:
$('#validFrom').datepicker('setDate', new Date());
alert('validFrom ...'+new Date());
Can anyone help me in converting and to set date in HTML.
Also it will be great if anyone can answer the difference of setting new Date() in controller class and HTML.

You will find this useful.
How to Convert JavaScript Date to Date in Java?
Basically, Java and Javascript date formats are slightly different and you need converters and parsers.

In Controller:
model.addAttribute("validFromDate", validDate);
In HTML:
var validFromDate = [[${validFromDate}]];
$('#validFrom').datepicker('setDate', new Date(validFromDate));

Related

how to convert firebase timestamp to only date and time in html?

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

SOAP UI - how to pass Current date time json in UTC format and RFC 7231 format in the header

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"

How to convert owlDateTime picker format

I am using owlDateTime datepicker."https://www.npmjs.com/package/ng-pick-datetime".And here is the slackblitz link."https://stackblitz.com/github/DanielYKPan/owl-examples/tree/date-time-picker?file=src%2Fapp%2Fbasic%2Fbasic.component.html".
From picker i am getting value like this "Tue Jan 08 2019 20:14:45 GMT+0530 (India Standard Time)" but i want to show it in this format "08/01/2019 20:14".
<label class="example-input-wrapper">
Date Time:
<input placeholder="Date Time:"
[(ngModel)]="dateTime"
[owlDateTimeTrigger]="dt" [owlDateTime]="dt">
<owl-date-time #dt></owl-date-time>
</label>
<h4>Value From Picker: {{dateTime}}</h4>
Here in this line " Value From Picker: {{dateTime}}" am getting value like this "Tue Jan 08 2019 20:14:45 GMT+0530 (India Standard Time)".
But in input field its showing in this format "1/8/2019, 8:25 PM".
But i want to show it in 24hours format.
Can anyone please help me how to do this using Angular 6.
I have searched a lot but not getting any solutions.Kindly help me out.
There are two way to convert date and time to any format
1.Using angular2-moment:
FYI:[https://www.npmjs.com/package/angular2-moment][1]
and the second way is using angular 6 date pipe
{{ dateTime | date: 'dd/MM/yyyy'}}

Datetime shift in Nodejs

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)

Timezone confusion with date picker and UTC times

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.