javascript - Formatting Date/Time in Typescript -


i've been having trouble trying date object in typescript format way want to.

i have class module defined as:

export class module {      constructor(public id: number, public name: string, public description: string,                   public lastupdated: date, public owner: string) { }      getnicelastupdatedtime(): string {          let options: intl.datetimeformatoptions = {             day: "numeric", month: "numeric", year: "numeric",             hour: "2-digit", minute: "2-digit"         };          return this.lastupdated.tolocaledatestring("en-gb", options) + " " + this.lastupdated.tolocaletimestring("en-gb", options);     } } 

when call method following code:

    let date = new date(1478708162000); // 09/11/2016 16:16pm (gmt)     let module = new module(1, "test", "description", date, "test owner");     console.log(module.getnicelastupdatedtime()); 

i end following printed in console:

'9 november 2016 16:16:02 gmt' 

what want see is:

09/11/2015 16:16 

i've had @ documentation at: https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/date/tolocaledatestring , still can't see i'm doing wrong (i know javascript api documentation i'm pretty sure that's typescript using under hood).

if want time out date want date.tolocalestring().

this direct console:

> new date().tolocalestring() > "11/10/2016, 11:49:36 am" 

you can input locale strings , format string precise output want.

https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/date/tolocalestring


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -