typescript 我的 angular 2 应用程序中的打字稿日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35197737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Date in typescript in my angular 2 application
提问by Mandersen
I'm in the middle of making some test data to my views, before I make the API calls to the API application.
在对 API 应用程序进行 API 调用之前,我正在为我的视图制作一些测试数据。
In a service in my angular 2 application, I have created a interface which looks like this:
在我的 angular 2 应用程序的服务中,我创建了一个如下所示的界面:
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:
我已经尝试过你在 javascript 中使用的 new Date() ,如下所示:
new Date("February 4, 2016 10:13:00");
But that does not work..
但这不起作用..
回答by Martin Vseticka
You can try in your browser's console that the following JS code works so it should work in TypeScript too:
您可以在浏览器的控制台中尝试以下 JS 代码是否有效,因此它也应该在 TypeScript 中有效:
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.
请添加您收到的错误。