Currently, I am developing a website for the company I work for. I am facing one issue at the moment, I have tested my local project on my computer, an android device, and an iPhone.
The problem
I am getting a Date object from the back-end (written in C#). I am trying to parse this to the following string: "HH:MM DD-MM-YYYY".
The method I have written does the job but for some reason, the time on my iPhone is two hours further than the time on my computer or android phone.
Code I am using to parse Date to string
let dateObject;
// InitialCreationDateTime contains the DateTime object that I have received from the back-end
if (this.initialCreationDateTime != null) {
dateObject = new Date(this.initialCreationDateTime);
} else {
dateObject = new Date();
}
// InitialCreationDateTime is nothing more then a string variable to store the final date string
this.initialCreationDateTimeString = dateObject.getHours() + ':' + ((dateObject.getMinutes() < 10 ? '0' : '') + dateObject.getMinutes()) + '\xa0\xa0' + dateObject.getDate() + '-' + (dateObject.getMonth() + 1) + '-' + dateObject.getFullYear();
Devices I have used for testing
- Huawei P20
- iPhone 5
I hope that my problem is clear, if not, do not hesitate to ask me for more information.
I hope someone can give me some insight/advice.
Thanks in advance