I want to show the upload date of a photo in my page, but I just can display the date according to the server time zone.
Let's suppouse I uploaded the photo at home the 12th at 19:30 GMT-5, so the server registered the 13th at 00:30.
What I want is to retrieve the date known by the user (12th 19:30).
What I've done is to get the timezone of the client and sustract that amount of minutes to the object Date, like this:
upload_date = response.upl_date;//This is the date I get from server (12:30)
var d = new Date();//Here I get the current date of client...
var timezone = d.getTimezoneOffset();//...to get the timezone offset in minutes (300)
var dd = new Date(upload_date);//Here I turn my server date into an object
dd.setMinutes(dd.getMinutes() - timezone);//Substract the minutes to the hour of the object
console.log(dd);//And voilá, I get 19:30, but the day keeps being 13
Despite the minutes affect the hours of the object Date, it doesn't affect the day, so it keeps being 13th instead of 12th.
Of course it works perfectly when, for example, it's 19:00 on server side and 14:00 on client side, but what can I do to change the days to fit with the timezone change? Should I try another way? Or some trick with if(){} ?