Get date inside jquery datepicker with not-ISO date format - javascript

I'm using jQuery datepicker to set the limit in a time series made with Highcharts for a personal project.
My date format is dd/mm/yyyy.
Following code works for sure till some weeks ago
onSelect: function () {
var minTime = $('input.highcharts-range-selector:eq(0)').datepicker("getDate").getTime();
var maxTime = $('input.highcharts-range-selector:eq(1)').datepicker("getDate").getTime();
}
But now I get following error:
"The specified value "03/02/2021" does not conform to the required format, "yyyy-MM-dd".
Searching I've understood that it depends on the fact that I'm using a format different from the ISO.
How I can fix this issue maintaining my date format?
Bonus question:
What could be changed from the last time that I've checked my site?
Thank you all

Related

In JavaScript/AngularJS, I can't seem to remove the "T" in a date field from the DB?

I must be missing something very obvious, but I could use help. I have an Angular web app, which is getting data from a MS Web API. The DTO object has two date fields. When those fields come in, there is a "T" in the date field.
e.g. 2017-05-01T03:43:55
For whatever reason, I can't seem to get rid of that darn "T" when using the date. I'd tried using a date format both on the calendar control that displays the date data, and using the JavaScript format() command. I also tried using the Javascript replace() command to replace the "T" with a space. And I tried using Moment.js to create a new date (which seems to fail and give me an invalid date).
var startDate = moment(badge.startDate).format('yyyy-MM-dd HH:mm:ss');
var startDate = badge.startDate.format(''yyyy-MM-dd HH:mm:ss'');
var startDate = moment(badge.startDate).replace('T',' ');
What am I missing? How should I be doing this? As far as I can tell, any of these should work?
You can create separate filter for that as below.
return (input) ? $filter('date')("2017-05-01T03:43:55", "yyyy-MM-dd HH:mm:ss") : '';
You can change for of date according to your requirements. You can see details Below.
https://docs.angularjs.org/api/ng/filter/date
use, don't build what already exists!
First visit moment js this component is very helpful and has many options which you can do with a date.
var date = moment(yourDate).format('YYYY-MM-DD');
format has a lot of options, you can find it on moment js documents.

Datepicker date format not comparing with moment date format

I have a datepicker on a registration page for selecting date of birth. The date picker works fine and if I capture its value (using javascript) it's value is correct (e.g. 4-12-1978)
In my function, which is using moment.js;
function checkBirthdate(dob) {
// dob is coming from $('#validation-dateofbirth').val()
var allowed = false;
var registerDate = moment().add(-18, "years").format("MM-DD-YYYY");
if (dob.isValid()) {
allowed = dob.isBefore(registerDate);
}
return allowed;
}
when testing, dob.isValid is an error. Okay that became obvious, I was trying to compare a moment date with a non moment date. Therefore, I have to convert the datepicker's output to a moment date.
Adding
dob = moment(dob);
//I also tried using
dob = moment(dob, "MM-DD-YYYY");
to the function should've worked, since the passed in dob value was in the same format shown in many moment docs (well, I'm assuming the value from the datepicker is a string like "4-12-2016"), but it doesn't.
How can I convert the value coming from the datepicker (I'm using the bootstrap datepicker) to a moment date?

ui grid date cellfilter, filtering date format is causing wrong date to show up

http://plnkr.co/edit/2dJAoMULBKD6frSSW7FN?p=preview
Please have a look at the plunkr above
I have give data as
date = "2008-12-10T04:00:00.000Z"
and applied cellfilter
cellFilter: 'date:"yyyy-MM-dd HH:mm"',
however the ending result it is showing as 2008-12-09 23:00, it should show 2008-12-10 04:00?
I think the problem is in the 'Z' that you putting in the strting Datetime. In this way you are indicating that this is a UTC date so that formatting transforms local.
You will get what you want if you change your code to:
date = "2008-12-10T04:00:00.000"

Angularjs date display

Hi I am trying to figure out how to display date properly using angularjs.
My system returns the date in this fromat
c_date="\/Date(1151470800000-0500)\/"
I dont know what format is it.
I am displaying it
using <span>{{pro.c_date | date:'medium')</span>
When i run this i get date printed in same format
"/Date(1151470800000-0500)/"
Can anyone suggest how to fix this so date can be displayed properly.
Thanks
the date that you're trying to use is a invalid date or maybe I don't know what format are the system using.
The problem is that angular.js requires a data object for can format it. Not a date string.
I suppose that the date is 1151470800000 miliseconds since the epoch least 0500 for adjust hours or something.
If this is correct, you only need to make c_date a Date object before pass to view.
c_date = "\/Date(1151470800000-0500)\/";
var the_date = eval("new "+c_date.replace(/\\|\//g, ''));
http://jsbin.com/zuwizoxe/3/
Regards!

Time Zone Offset Calculations

Let's suppose the server gives the date in this format:
var date = '2012-08-08T15:04:33+0200';
As you can see the previous date has a Timezone offset of two hours.
Let's suppose I need to display the same date in different places having different timezone.
What is the proper way to display the date in different clients having the different time zone using moment.js
I did try the following but I am not sure because I cannot test it.
moment(date, "YYYY-MM-DDTHH:mm:ss").fromNow();
According the documentation it should be enough just passing the following parameter ´Z´ or ZZ according your date format.
So in your case it should be:
var date = '2012-08-08T15:04:33+0200';
moment(date, "YYYY-MM-DDTHH:mm:ssZ").fromNow();

Categories