Different ways to convert a date object to instant type in Angular without considering the timestamp

I have a function that converts a Date to a timestamp, but it includes the timezone, which I don't want. I only need the date with no timezone information in Instant type.

convertDateToTimeStamp(date: any) {
  return Date.parse(date) / 1000;
}

Before using convertDateToTimeStamp(), the date value is **Fri Mar 24 2017 00:00:00 GMT-0400 (Eastern Daylight Time)**

After using convertDateToTimeStamp(), the date value is **1490328000** which is **Thursday, November 26, 2015 12:00:00 AM GMT-05:00**

I want the date to remain the same across all timezones, without any GMT added to it.

Answer №1

changeDateFormatToUnix(dateValue: any) {
  return new Date(dateValue).getTime();
}

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

Display excerpts of code within an Angular application within the HTML segment

I'm currently developing a tutorial page using Angular where I intend to display code snippets in various programming languages such as 'Java', 'TypeScript', 'C#', and 'Html'. Although there is a snippet called ...

Unable to utilize the concatMap() method in conjunction with the angular2 Http feature

Looking to chain multiple http requests, the number of requests can vary and they are not dependent on the previous request's result. The goal is to only keep the returned object from the last request. Received two suggestions on this forum thread. T ...

Transform the code provided by bundleMDX into an HTML string specifically for RSS, all the while utilizing the mdx-bundler

I am currently working on developing an RSS reader and I need to convert the code returned by bundleMDX into a string. This is necessary so that I can utilize it with ReactDOMServer.renderToStaticMarkup(mdx) in my project. You can find a similar implement ...

Is there a way I can utilize the $timeout and $interval functionalities that were implemented in angular.js, but for the Angular framework?

When working with Angular.js, I made use of the $timeout and $interval functions (which are similar to setInterval and setTimeout in JavaScript). $timeout(function(){}) $interval(function(){},5000) To stop the interval, I utilized $interval.cancel($scop ...

Differences between ng build --prod and ng --build aot in Angular 7

Recently, I successfully built an Angular 7 application using the command ng build --prod. However, I am now facing a dilemma regarding ng build --aot versus ng build --prod. Our application is currently deployed on ..., and although it runs successfully ...

Steps for deleting an item from a list based on a specific condition in Ionic 2

<ion-list> <ion-list-header> <span ion-text bold color="primary"> My Application</span> </ion-list-header> <div *ngIf="userStatus!='Registered' " > <ion-item *ngFor="let type of options" (click)="close( ...

Typescript encountering onClick function error during the build process

My current challenge involves creating a submit function for a button in my application. However, when I attempt to build the project, I encounter a typing error that is perplexing me. Despite trying various methods, I am unable to decipher how to resolve ...

Angular2 is experiencing issues with child routing not functioning properly unless useAsDefault is set to true

I am encountering an issue with my Angular 2 routing program. When I remove useAsDefault: true, the routing stops working and I receive the following error message: EXCEPTION: Link "["Pen"]" does not resolve to a terminal instruction. in [['Pen&a ...

What is the best way to use lodash to group objects that contain nested objects?

Currently utilizing Typescript in conjunction with Lodash! Upon retrieving data from the database, here is the resulting output: [ { "unitPrice": 0.01, "code": "92365524", "description": "Broto gr ...

Having trouble opening a JPEG file that was generated using the Writefile Api in Ionic-Cordova

Currently, I am using the writeFile API to create a JPEG image. The process is successful and the image is stored in the directory as expected. However, when I try to open the file manually from the directory, I encounter an error message saying "Oops! Cou ...

Having trouble with GraphQL Explorer and Express Sessions compatibility?

Struggling to implement a login system using GraphQL and Express, but facing issues with session persistence. Despite logging in, req.session.userId remains undefined. Code snippet: (async () => { await connect(process.env.MONGO_URI!, { dbName: "ex ...

TypeScript's version of Java's enum (or C#'s structure)

I'm facing the challenge of creating an enum in Typescript that mimics the functionality of Java enums. In TypeScript, only integer-based enums like C# are supported, unlike in Java where we can have custom objects with non-integer related properties ...

Access your Angular 2 application on an external device during the development process

Is there a way to view your app in an external device like a cell phone web browser, instead of just running npm start and viewing it in your desktop browser? ...

Is there a different option similar to forkJoin for handling incomplete observables?

constructor( private route: ActivatedRoute, private http: Http ){ // Retrieve parameter changes observable let paramObs = route.paramMap; // Fetch data once only let dataObs = http.get('...'); // Subscribe to both ob ...

Angular 2 keypress validation: Ensuring data integrity through real-time input verification

I am currently facing an issue with implementing number validation in my Angular2 project. I am struggling to replicate the JavaScript code provided below. Here is the HTML: <input type="text" class="textfield" value="" id="extra7" name="extra7" onkeyp ...

Angular Service failing to connect with API endpoint

I have been experimenting with a new service called vpnblocker, designed to identify whether a user is utilizing a VPN or not. I am closely following the specified documentation and referencing the API variables. Despite setting up my angular service to ma ...

Enhance your AJAX requests with a retry mechanism when incorrect payloads are sent in subsequent requests

Currently, I am working with Angular and RXJS and facing an issue where I need to execute up to 5 AJAX requests concurrently. Each request should be attempted up to 3 times before giving up and returning an error. The problem I'm encountering is that ...

What is the best way to retrieve an array that was created using the useEffect hook in React?

Utilizing the power of useEffect, I am fetching data from two different APIs to build an array. My goal is to access this array outside of useEffect and utilize it in the return statement below to render points on a map. However, when trying to access it ...

Having trouble connecting 'chartData' to a 'div' in Angular 2 because it is not recognized as a valid property?

While working on my Angular project, I encountered the following error that I have been unable to resolve: EXCEPTION: Uncaught (in promise): Error: Template parse errors: Can't bind to 'chartData' since it isn't a known property of ...

Understanding the Relationship Between Interfaces and Classes in Typescript

I’ve come across an interesting issue while working on a TypeScript project (version 2.9.2) involving unexpected polymorphic behavior. In languages like Java and C#, both classes and interfaces contribute to defining polymorphic behaviors. For example, i ...