Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date in typescript in my angular 2 application

I'm in the middle of making some test data to my views, before I make the API calls to the API application.

In a service in my angular 2 application, I have created a interface which looks like this:

export interface amendmentBookings {
    bookingNumber: string;
    outboundDate: Date;
    returnDate: Date;
    route: string;
    Passengers: string;    
    vehicleType: string;
}

I have also created an array which must consist of type to this interface. The code looks like this:

var bookings: amendmentBookings[] = [
    {
        bookingNumber: "123456789",
        outboundDate: 
        returnDate:
        route: "Dünkirchen - Dover",
        vehicleType: "Car 1.85m x 4.5m",
        Passengers: "1 adult and 1 child"
    },
]

How can I insert a date in my test data?

I have tried with the new Date() which you use in javascript, like this:

new Date("February 4, 2016 10:13:00");

But that does not work..

like image 450
Mandersen Avatar asked Dec 10 '22 18:12

Mandersen


1 Answers

You can try in your browser's console that the following JS code works so it should work in TypeScript too:

 var bookings = [{
     bookingNumber: "123456789",
     outboundDate: new Date("February 4, 2016 10:13:00"),
     returnDate: new Date("February 4, 2016 10:13:00"),
     route: "Dünkirchen - Dover",
     vehicleType: "Car 1.85m x 4.5m",
     Passengers: "1 adult and 1 child"
}];

console.log(bookings)

Please add an error you get.

like image 80
Martin Vseticka Avatar answered Feb 27 '23 17:02

Martin Vseticka