Fetching contributors…
Cannot retrieve contributors at this time
44 lines (32 sloc) 927 Bytes
title version

As of version 2.13.0, Moment includes a typescript definition file.

Install via NPM

npm install moment

Import and use in your Typescript file

import * as moment from 'moment';

let now = moment().format('LLLL');

Note: If you have trouble importing moment, try adding "allowSyntheticDefaultImports": true in compilerOptions in your tsconfig.json file and then use the syntax

import moment from 'moment';

Locale Import

To use moment.locale you first need to import the language you are targeting.

import * as moment from 'moment';
import 'moment/locale/pt-br';

console.log(moment.locale()); // en
console.log(moment.locale()); // en
console.log(moment.locale()); // pt-BR