gb-date-formatter
v1.7.0
Published
minimal date formatting
Downloads
94
Readme
gb-date-formatter
A partial re-engineering of AngularJs's date formatting.
Install
$ npm install gb-date-formatter
API
To use the DateFormatter
class in a TypeScript file
import { DateFormatter } from "gb-date-formatter";
const formatter = new DateFormatter();
console.log(formatter.format(new Date("1924-02-25T07:44:40.755Z"), "MMMM y"));
// February 1924
To use the DateFormatter
class in a JavaScript file
var DateFormatter = require("gb-date-formatter").DateFormatter;
var formatter = new DateFormatter();
console.log(formatter.format(new Date("1924-02-25T07:44:40.755Z"), "MMMM y"));
// February 1924
To use the DateFormatter
class in an Angular pipe
wrap the gb-date-formatter in an Angular Pipe
import { Pipe, PipeTransform } from '@angular/core';
import { DateFormatter, FormatString } from 'gb-date-formatter';
@Pipe({ name: 'gbCustomDate' })
export class CustomDatePipe implements PipeTransform {
private static namedFormats: { [name: string]: FormatString; } = {
medium: 'MMMM y',
long: 'EEE MMM d, y h:mm a'
};
private formatter: DateFormatter = new DateFormatter('en-US');
public transform(value: Date, fmt: string): string {
return this.formatter.format(value, CustomDatePipe.namedFormats[fmt]);
}
}
and add the directive to a template
<td [title]="friend.birthday | gbCustomDate:'long'">{{friend.birthday | gbCustomDate:'medium'}}</td>