How to use the globalize.dateFormatter function in globalize

To help you get started, we’ve selected a few globalize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github globalizejs / globalize-compiler / test / unit / fixtures / basic.js View on Github external
var like;
var Globalize = require("globalize");

/**
 * Date
 */

// Use dateFormatter.
var dateFormatter = Globalize.dateFormatter({time: "medium"});
console.log(dateFormatter(new Date()));

// Use formatDate.
console.log(Globalize.formatDate(new Date(), {date: "medium"}));

// Use formatDate in specific time zones.
console.log(Globalize.formatDate(new Date(), {
	datetime: "full",
	timeZone: "America/Sao_Paulo"
}));

// Use dateToPartsFormatter.
var dateToPartsFormatter = Globalize.dateToPartsFormatter({time: "long"});
console.log(dateToPartsFormatter(new Date()));

// Use formatDateToParts.
github globalizejs / globalize / examples / app-npm-webpack / app / index.js View on Github external
// Standalone table.
var numberFormatter = Globalize.numberFormatter({ maximumFractionDigits: 2 });
document.getElementById( "number" ).textContent = numberFormatter( 12345.6789 );

var numberCompactFormatter = Globalize.numberFormatter({
	compact: "short",
	minimumSignificantDigits: 1,
	maximumSignificantDigits: 3
});
document.getElementById( "number-compact" ).textContent = numberCompactFormatter( 12345.6789 );

var currencyFormatter = Globalize.currencyFormatter( "USD" );
document.getElementById( "currency" ).textContent = currencyFormatter( 69900 );

var dateFormatter = Globalize.dateFormatter({ datetime: "medium" });
document.getElementById( "date" ).textContent = dateFormatter( new Date() );

var dateWithTimeZoneFormatter = Globalize.dateFormatter({
	datetime: "full",
	timeZone: "America/Sao_Paulo"
});
document.getElementById( "date-time-zone" ).textContent = dateWithTimeZoneFormatter( new Date() );

var _dateToPartsFormatter = Globalize.dateToPartsFormatter({ datetime: "medium" });
var dateToPartsFormatter = function( value ) {
	return _dateToPartsFormatter( value, {
		datetime: "medium"
	}).map(function( part ) {
		switch(part.type) {
			case "month": return "<strong>" + part.value + "</strong>";
			default: return part.value;
github dojo / framework / tests / i18n / unit / util / globalize.ts View on Github external
'assert method returns a method'() {
				const locale = 'fr';
				const value = new Date();
				const options: DateFormatterOptions = { datetime: 'full' };

				let formatter = globalizeDelegator('dateFormatter', {});
				assert.strictEqual(formatter(value), Globalize.dateFormatter()(value));

				formatter = globalizeDelegator('dateFormatter', {
					optionsOrLocale: options
				});
				assert.strictEqual(formatter(value), Globalize.dateFormatter(options)(value));

				formatter = globalizeDelegator('dateFormatter', {
					locale,
					optionsOrLocale: options
				});
				assert.strictEqual(formatter(value), new Globalize('fr').dateFormatter(options)(value));
			}
		}
github globalizejs / globalize / examples / app-npm-webpack / app / index.js View on Github external
document.getElementById( "number" ).textContent = numberFormatter( 12345.6789 );

var numberCompactFormatter = Globalize.numberFormatter({
	compact: "short",
	minimumSignificantDigits: 1,
	maximumSignificantDigits: 3
});
document.getElementById( "number-compact" ).textContent = numberCompactFormatter( 12345.6789 );

var currencyFormatter = Globalize.currencyFormatter( "USD" );
document.getElementById( "currency" ).textContent = currencyFormatter( 69900 );

var dateFormatter = Globalize.dateFormatter({ datetime: "medium" });
document.getElementById( "date" ).textContent = dateFormatter( new Date() );

var dateWithTimeZoneFormatter = Globalize.dateFormatter({
	datetime: "full",
	timeZone: "America/Sao_Paulo"
});
document.getElementById( "date-time-zone" ).textContent = dateWithTimeZoneFormatter( new Date() );

var _dateToPartsFormatter = Globalize.dateToPartsFormatter({ datetime: "medium" });
var dateToPartsFormatter = function( value ) {
	return _dateToPartsFormatter( value, {
		datetime: "medium"
	}).map(function( part ) {
		switch(part.type) {
			case "month": return "<strong>" + part.value + "</strong>";
			default: return part.value;
		}
	}).reduce(function( memo, value ) {
		return memo + value;