Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Datepicker shows one day behind when using yyyy-MM-dd format #2628

Closed
bohmanart opened this issue Aug 25, 2014 · 23 comments
Closed

Datepicker shows one day behind when using yyyy-MM-dd format #2628

bohmanart opened this issue Aug 25, 2014 · 23 comments

Comments

@bohmanart
Copy link

screen shot 2014-08-25 at 9 41 29 am

@kz26
Copy link

kz26 commented Aug 27, 2014

+1, can confirm.

@charger513
Copy link

I have the same issue, any solutions?

@awb
Copy link

awb commented Sep 9, 2014

This is probably a time zone issue, try displaying model.toISOString() to see.

@charger513
Copy link

@awb You are right 👍 . I could solve this adding timezone with getTimezoneOffset() :)

@bohmanart
Copy link
Author

So is this fixable on my end or is this a bug within the directive? I'm passing a date like "2014-09-10" and the datepicker dropdown is displaying 2014-09-09 but the input is correct.

@kz26
Copy link

kz26 commented Sep 10, 2014

I fixed it simply by converting all date strings (my backend returns ISO dates like 2014-09-10) into date objects in my controller.

@charger513
Copy link

This is how I fixed it. I added my timezone

var d = new Date('yourDate');
d.setMinutes( d.getMinutes() + d.getTimezoneOffset() );

'd' should be the correct date

@mgaerber
Copy link

Please put this in the docs - I just realized this as well (too late).

For yyyy-MM-dd it does not make sense, since the user is not entering a time value, so time is always T00:00:00 (+/- the gmt offset when converted to string)

@wesleycho
Copy link
Contributor

This should now be addressed in 0.14.3.

There are still some timezone issues, i.e. the weakness in not being able to configure it, but one can set the timezone used by the datepicker via setting an initial model date value with the appropriate timezone.

@shrimpwagon
Copy link

This is still not fixed.

format: {
    toDisplay: function(date, format, language)
    {
        console.log(date);
    },
toValue: function(date, format, language)
    {
        return date;
    }
}

This outputs:

Tue Sep 06 2016 20:00:00 GMT-0400

Today is the 7th!

@charlie-wasp
Copy link

I guess, I am experiencing the same issue right now, version 1.3.3

@DavidRogersDev
Copy link

I'm experiencing this same issue, and I'm not even concerned with the time of day. I just want to be able to choose a day. Picker keeps picking the day before. Not a good outcome for me.

@elijahlofgren
Copy link

I ran into this yesterday and found the solution is to set the timezone option to utc and the date is no longer off by one. The syntax for doing that is here: #4837 (comment)

@DavidRogersDev
Copy link

Thanks Elijah. But that did not resolve the issue for me. I really wish they would fix this bug, rather than just close the many Issues that people raise which reference it.

@gbrits
Copy link

gbrits commented Mar 13, 2017

If you'd like to hardcode a timezone, you could do what I did. As @charger513 mentioned, you can set the minutes along with the timezone offset -- but instead of determining your current timezone automatically, you could substitute the timezone offset with the amount of minutes - in my case, my local timezone was returning -660 (UTC-11). But I needed it to be 480 (UTC+08).

var d = new Date('yourDate');
d.setMinutes( d.getMinutes() + 480 );

I was then finally getting the output I wanted - as my PHP backend counterpart was aligned to the UTC+08 timezone.

Find your timezone minutes offset here: https://forbrains.co.uk/international_tools/earth_timezones

@gauravgtex007
Copy link

I have found a way. convert that date to string first.
here is the code.

 var SelectDate = $scope.GetFormattedDate(Date.parse($("#Date").datepicker("getDate")));            
     $scope.GetFormattedDate = function (CalDate) {
            var re = /-?\d+/;
            var WDate = CalDate.toString();
            var m = re.exec(WDate);
            var lastDate = new Date(parseInt(m[0]));
            var mm = lastDate.getMonth() + 1;
            var dd = lastDate.getDate();
            var yyyy = lastDate.getFullYear();
            var formattedDate = mm + '/' + dd + '/' + yyyy;
    
            return formattedDate;
        }

Now Pass SelectDate to your controller.
bingo problem has been resolved :)

@mvelebit
Copy link

Can't believe this is still a bug..

@maverick1812
Copy link

I solved this issue by giving the Date field in Backend as Edm.DateTimeOffset (this will be a Timestamp field in ABAP) & converting the timestamp field to Date & Time by using function module - IB_CONVERT_FROM_TIMESTAMP.

@vishnucr
Copy link

if you are using moment, you can user the 'utc date'
moment.utc('23-12-2011')

@NDMCreative
Copy link

This works for me

var DatePickerDate ='Thu Aug 09 2018 00:00:00 GMT+0100 (British Summer Time)';

var myDate = new Date(DatePickerDate).toISOString();

so myDate is now 2018-08-08T23:00:00.000Z

@ricksonmenezes
Copy link

ricksonmenezes commented Nov 23, 2018

If you are using Java-Hibernate, use the Date as type String in your Model(POJO) when reaching the controller to collect ModelAttribute. This issue occurs If you use it as type DateTime in your Java.

@junaid003
Copy link

+1

@D252874
Copy link

D252874 commented Apr 5, 2019

when will this be fixed I still got the same problem using the latest version of angular and material. but I am not using yyyy-mm-dd I am just using standard material date picker.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests