Error in Ionic 2: 'Date' object is not functioning properly on iOS devices

Having an Ionic 2 app, my challenge is to compare two dates. Initially, I have a date in string format like so: '2017-03-29 09:13:00'

My approach involves transforming it into a Date Object:

let myDate = new Date('2017-03-29 09:13:00');

The next step is comparing my date with the current day's date:

let today: Date = new Date();
let myDate = new Date('2017-03-29 09:13:00');
if(today == myDate) {
  return something...
}

This code functions well with ionic serve and ionic run android (on an android device). The resulting date format is "Wed Mar 29 2017 09:13:00 GMT+0200 (Central Europe Daylight Time)"

However, I encountered some issues on IOS devices.

let myDate = new Date('2017-03-29 09:13:00');
yields 'null'

and

let today: Date = new Date(); gives me this date format: "2017-03-30T09:17:01.303Z"

I am puzzled by these inconsistencies and seeking guidance on how to obtain the correct Date type on IOS devices.

Answer №1

One suggestion is to consider utilizing moment.js in the following way:

moment('2017-03-29 09:13:00').toDate()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What strategies can be implemented to steer clear of utilizing global variables?

I have been advised against using global variables. One of them is used to toggle client-side validation on and off. The other two are used to control my drop-down menu. If these shouldn't be global variables, where should I store them? /* Global ...

Creating DOM elements upon successful completion of an AJAX request with jQuery has never been easier. Here's a

I'm currently working on a project where I am dynamically creating a list of checkboxes using jQuery's $.ajax method. function load() { $.ajax({ type: "POST", url: "*************", data: "************ ...

Looking for advice on using the ternary operator in your code? Let us

In my JS file, the code $scope.button = id ? "Edit" : "Add"; is functioning correctly. I am trying to implement it in the View like this: <button name="saveBtn" class="btn btn-primary" tabindex="10">{{person.id ? 'Edit' : 'Add&ap ...

Implementing manual updates for the bootstrap color picker

I have integrated a color picker from Bootstrap into my project. You can find the color picker here: To change the background color of an element on my page, I am using the following code: <input type="text" id="mypicker" name="mypicker" value="" cla ...

Sharing JSON data between two Backbone views

Could you provide some guidance on how to pass dynamic JSON data from one view to another? In the initial view, I am creating the JSON object using the following syntax: json.push({ first: value, second: value }); ...

Angular's ngMock $httpBackend feature now allows developers to split their mocks into separate files for

I am currently developing a large angular application that requires mocking the entire API within the browser, also known as backend-less development. Each section and view in my application will have its own mock definitions. I am aware that I can utiliz ...

Changing background color of image dropdown in JavaScript

Seeking the functionality of a combobox in Java for an HTML page generated using PHP. Looking to incorporate an icon, text, additional information, and background color. Data can be sourced from a JSON file or through a PHP query on a MySQL DB. Discovered ...

Disabling the scroll-bar feature exclusively

Is there a way to disable the scroll-bar functionality in Chrome without hiding it using overflow:hidden? I want the scroll-bar to remain visible. I'm looking for something similar to this: http://prntscr.com/ai5y9k Any assistance would be greatly a ...

Is there a way for me to extract a smaller segment from an ID label?

I am working on a web development project and I have a set of buttons within a specific section. Each button has an id in the format of #balls-left-n, where n ranges from 1 to 15. My goal is that when a user clicks on one of these buttons, I want to extra ...

Struggling with a component that won't load in JSX?

Having some difficulty with React not rendering data associated with a component's props: import React from 'react'; import {ItemListing} from './ItemListing.js'; export var SearchResults = React.createClass({ render: functi ...

Using Axios with Node.js throws an error: "ReferenceError: XMLHttpRequest is not defined."

When sending a GET request using a basic axios configuration, I encounter the following issue: var Axios = axios.create({ baseURL: myBaseUrl, headers: {'content-type': 'application/json'} }); Axios.get(url) The er ...

Discovering the Power of Lazy Loading in Angular 2 with Ahead of Time Compilation

After successfully generating .ngfactory files with the ngc compiler and updating my main.ts file with "platformBrowser().bootstrapModuleFactory(AppModuleNgFactory)", I encountered an issue. app.routes.ts const appRoutes: Routes = [ { path: '&ap ...

The select menu default value is not displaying properly after the update to select2 version 4.0.3

After updating the select2 package from version v4.0.0 to v4.0.4, I noticed that the default value of the select menu was no longer appearing as expected: https://i.sstatic.net/UO3yZ.jpg For those interested, here is a link to my code on JSBin: view jsbi ...

Passing identical props to multiple children in React

When working with my React App, I decided to implement a star rating system for the posts fetched from an API and displayed on the main page. To achieve this, I created a function that utilizes a Rate component to rate each post using the ratePost action. ...

Angular integration with backend for social login using the laminas API tool

Can somebody guide me in the right direction? I'm currently working on integrating Google login into my Angular project, with my backend using the Laminas API tool framework. It seems like this Angular module could help with that. Check it out here: ...

Having trouble configuring the animated splash screen in Ionic 4 and above

What I'm looking for : I want an animated splash screen to appear when the app is being opened. What I've tried : I used a video from this link https://www.youtube.com/watch?v=-c0htV-kfm8 as reference and added the following code. However, inste ...

Retrieve information in Angular stored as an array of objects

I am having trouble retrieving the data stored in template_A columns col_1 and col_2 to display it in table format. Instead of getting the actual data, I keep getting [object,object]. Can someone help me figure out how to access the data stored as an array ...

Experiencing Issues with File Downloading on Express Server with Axios and Js-File-Download Library

I developed a feature on my express server that allows users to download a file easily. app.post("/download", (req, res) => { let file_name = req.body.name; res.download(path.join(__dirname, `files/${file_name}.mp3`), (err) => { ...

Configuring modules using Sass, CSS-Modules, Webpack, React, and TypeScript

I'm facing an issue with extracting types from my .scss files. I've tried various configurations and solutions, but nothing seems to work. Specifically, my goal is to utilize modules in a React app with TypeScript. Below is my webpack configura ...

The child module's services are accessible and utilized by the components of the parent module

I have an Angular application structured as follows: Data Module --> Data Component --> Data Service List Module --> imports Data Module --> List Component --> which calls Data Component --> Parent List Compone ...