while searching date of birth in frontend( angularjs) the request is going with different date of birth to backend spring
i am sending date of birth in this format:
Sun Aug 15 1999 00:00:00 GMT+0530 (India Standard Time)
request url to backend:
dob=1999-08-14T18:30:00.000Z
You can convert date into the required format using the angular date filter, Have look here AngularJS date filter .
You might be looking for something like this: {{ date_expression | date : 'yyyy-MM-ddTHH:mm:ss.sssZ' : timezone}}
Related
i am working in ember with moment js. this below code convert my local time to UTC format
{{ utc (moment timeEntry 'YYYY-MM-DD HH:mm:ssZ')}}
and output is like Tue Nov 26 2019 00:00:00 GMT+0000.
But i want to display the output like Tue, 26 Nov, 2019.
i tried moment-format for utc time but no luck
The YYYY-MM-DD HH:mm:ssZ part of the code is what determines the output. You can read up on the other possible outputs here.
To get your desired output of Tue, 26 Nov, 2019, you should use {{ utc (moment timeEntry 'ddd, D MMM, YYYY')}}}
This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Closed 4 years ago.
I'm trying to hit a soccer sports API which includes date in the format of yyyy-mm-dd, only the scores from that date to current date will be displayed. The current date is chosen by user using a calendar but when the user chooses the date from calendar, it gets displayed in ISO format as "Fri Aug 17 2018 00:00:00 GMT +0545 (Nepal Time)" . I want to convert this date in the front end in the yyyy-mm-dd format and send it to the API Url in back end. I'm using AngularJS and Java. How do I convert the full ISO date into that format?
Based on that output it sounds like your date is stored as a JavaScript date object (see: https://www.w3schools.com/js/js_dates.asp)
To get the string you want, one solution would be to take the value of your input (I'll call it d) and do the following (I assume you have momentjs loaded:
var datestring = moment(d).format('YYYY-MM-DD')
datestring should now include the date in the format you want... if for some reason d is a string instead of a date object, you can create a parsing pattern following the momentjs doc here: https://momentjs.com/docs/#/parsing/
Assuming you have a JavaScript Date object to work with, you can do this in plain JS:
var datestring = dateobj.toISOString().substring(0, 10); // 'yyyy-MM-dd'
If you only have the display string ("Fri Aug 17 2018 00:00:00 GMT +0545 (Nepal Time)"), you can first convert that into a Date object with this:
// displaystring = "Fri Aug 17 2018 00:00:00 GMT +0545 (Nepal Time)";
var dateobj = new Date(displaystring);
...and then do the datestring conversion above.
We have a Java new Date(); which returns the date as below:
Mon Feb 19 19:51:21 IST 2018
And the javascript Date() function returns the date in a format like below:
Mon Feb 19 2018 20:31:37 GMT+0530 (India Standard Time)
I have a rest webservice which accepts the date in exact format as that of Java's date (Mon Feb 19 19:51:21 IST 2018).
In an ajax request, I am passing an xml content which has a date tag along with other xml tags like id and author. Example below. If I send an xml like below, the date field gets ignored as the Date format expected in the rest webservice is different than the one below.
<message>
<autor>User2</autor>
<date>Mon Feb 19 2018 20:02:03 GMT+0530 (India Standard Time)</date>
<id>1</id>
<message>Message2</message>
</message>
Use .getTime() to get date value in milliseconds in JS like this:
var date = new Date().getTime();
And then on your Java back-end use value in milliseconds from JS to create date object:
Date date = new Date(dateFromJS);
And you can also add some formating to it:
String formatted = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
i am using nodejs to connect to mySql and connection works.
while using query such as
SELECT * from someTable
i get the required results. But the problem is that i am having
a column which stores date is having the given format.
before sending the data i need this format to be converted and vice versa
file_date : Wed Jan 01 2014 05:34:53 GMT+0530 (IST)
This is format i am getting
i am unable to send params with Date in this format from client side
so i need to convert this data to "DD-MM-YYYY" format.i need this way so that i can pass params in "DD-MM-YYYY" and fetch data date wise
Simple Approach
If you know your date format is supported in Moment, then the simplest approach is to construct a moment object and format it.
var file_date = 'Wed Jan 01 2014 05:34:53 GMT+0530 (IST)';
var formatted = moment(file_date).format('DD-MM-YYYY');
Deprecation Warning:
However, at some point support for non ISO date formats was deprecated. It will in some cases still work but you should be warned (per the deprecation warning message):
Deprecation warning: value provided is not in a recognized ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non ISO date formats are discouraged and will be removed in an upcoming major release.
Workaround
Instead, if you know the format of an input string, you can use that to parse a moment.
var s = 'Wed Jan 01 2014 05:34:53 GMT+0530 (IST)';
var m = moment(s, 'ddd MMM DD YYYY hh:mm:ss [GMT]ZZ').format('MM-DD-YYYY');
console.log(m);
<script src="https://momentjs.com/downloads/moment.min.js"></script>
When specifying a format manually like this, it helps to have the format documentation handy: https://momentjs.com/docs/#/displaying/format/
I am trying to format a date from javascript as follows.
var startDate = new Date('Fri Oct 12 2012 10:15:00 GMT+0530 (India Standard Time)');
var dateString = startDate.format("ddd MMM dd yyyy"));
var timeString = startDate.format("h:mm tt"));
When running this from my machine i got both date and time string as expected. like
dateString as Fri Oct 12 2012 and timeString as 10:15 AM.
But in live server i am getting dateString as Fri 1515 12 2012 and timeString as 10:1010 AM. I think the issue is with format of Month and Minute.
The local server is here in India and the live server is in Us. So i am not sure, is it related with the date format in different culture?
What is the best way to format the date string from javascript. Is i am doing the right thing to format date string.
By using startDate.getDate() & startDate.getDay() & startDate.getFullYear()
view this http://www.w3schools.com/jsref/jsref_obj_date.asp it helps you.By using this date object properties you can get your appropriate result