How to use dateformat - 10 common examples

To help you get started, we’ve selected a few dateformat 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 DefinitelyTyped / DefinitelyTyped / types / dateformat / dateformat-tests.ts View on Github external
* https://github.com/felixge/node-dateformat#usage
 */

import * as dateFormat from 'dateformat';
const now = new Date();

// Basic usage
dateFormat(now, 'dddd, mmmm dS, yyyy, h:MM:ss TT');
// Saturday, June 9th, 2007, 5:46:21 PM

// You can use one of several named masks
dateFormat(now, 'isoDateTime');
// 2007-06-09T17:46:21

// ...Or add your own
dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
dateFormat(now, 'hammerTime');
// 17:46! Can't touch this!

// You can also provide the date as a string
dateFormat('Jun 9 2007', 'fullDate');
// Saturday, June 9, 2007

// Note that if you don't include the mask argument,
// dateFormat.masks.default is used
dateFormat(now);
// Sat Jun 09 2007 17:46:21

// And if you don't include the date argument,
// the current date and time is used
dateFormat();
// Sat Jun 09 2007 17:46:22
github rodrigosetti / pet-monitor / cloud / src / controllers / events.js View on Github external
/* jshint node:true, esversion:6 */

const dateformat = require('dateformat');
const winston = require('winston');
const db = require('../db');

dateformat.masks.dayMinute = "m/d/yyyy h:MM tt";

module.exports = (req, res) => {
    let query = req.query.q || '24';
    let parts = query.trim().split('-');
    let sinceH = parseInt(parts[0]);
    let toH = parts.length > 1 ? parseInt(parts[1]) : 0;
    let now = Date.now() / 1000;
    let sinceTS = now - (sinceH * 3600);
    let toTS = now - (toH * 3600);

    db.getEvents(
        sinceTS, toTS,
        (err, rows) => {

            if (err) {
                winston.error(err);
github rodrigosetti / pet-monitor / index.js View on Github external
/* jshint node:true, esversion:6 */

let SerialPort = require('serialport');
let express = require('express');
let winston = require('winston');
let config = require('config');
let sqlite3 = require('sqlite3');
let morgan = require('morgan');
let dateformat = require('dateformat');

dateformat.masks.dayMinute = "m/d/yyyy h:MM tt"

const RAW_TARE = config.get('raw_tare');
const CONTAINER_TARE = config.get('container_tare');
const CALIBRATION_G = config.get('calibration_g');
const STABLE_N = config.get('stable_n');

winston.level = config.get('log.level');
if (config.get('log.cli_mode')) {
    winston.cli();
}

let db = new sqlite3.Database('data.db');

let port;

function atExit(exitCode) {
github 3846masa / lit-date / benchmarks / src / advanced.bench.js View on Github external
import moment from 'moment';
import 'moment/locale/ja';
import { DateTime } from 'luxon';
import fecha from 'fecha';
import { format as dateFnsFormat } from 'date-fns';
import dateFnsLocaleJa from 'date-fns/locale/ja';
import dateformat from 'dateformat';
import litdate from 'lit-date';

const date = new Date('2000-01-06T12:34:56.789Z');
const expected = '1月6日(木)';

// Prepare
const dayOfWeekToName = ({ dayOfWeek }) => ['日', '月', '火', '水', '木', '金', '土'][dayOfWeek];
Object.assign(dateformat.i18n, {
  dayNames: ['日', '月', '火', '水', '木', '金', '土'],
});
Object.assign(fecha.i18n, {
  dayNamesShort: ['日', '月', '火', '水', '木', '金', '土'],
});

suite('Advanced usage', () => {
  benchmark('moment', () => {
    const actual = moment(date)
      .locale('ja')
      .format('M月D日(ddd)');
    console.assert(actual === expected);
  });
  benchmark('luxon', () => {
    const actual = DateTime.fromJSDate(date)
      .setLocale('ja')
github actorcloud / ActorCloud / ui / src / components / EmqCrud.vue View on Github external
}
      }
      // Header joint filtering
      /* eslint-disable */
      if (Object.keys(tableFilterConditions).length !== 0) {
        for (let item in tableFilterConditions) {
          if (tableFilterConditions[item] !== undefined) {
            params[item] = tableFilterConditions[item]
          }
        }
      }
      // Time search
      if (searchTimeName && searchTimeValue
        && searchTimeValue.length > 0 && searchTimeValue[0] && searchTimeValue[1]) {
        const startTime = dateformat(searchTimeValue[0], 'yyyy-mm-dd HH:MM:ss')
        const endTime = dateformat(searchTimeValue[1], 'yyyy-mm-dd HH:MM:ss')
        params.start_time = startTime
        params.end_time = endTime
        params.time_name = searchTimeName
      }
      httpGet(this.url, { params, ...this.httpConfig }).then((response) => {
        if (response.data.meta) {
          this.total = response.data.meta.count || 0
          if (response.data.items.length === 0 && response.data.meta.page > 1) {
            this.currentPageChanged(this.currentPage - 1)
          }
        }
        const records = response.data.items
        this.searchLoading = false
        this.loading = false
        this.records = records
        if (this.isDefaultExpand) { // Expands the first row when there is a default expanded row
github Financial-Times / x-dash / components / x-teaser / src / RelativeTime.jsx View on Github external
export default ({ publishedDate, firstPublishedDate }) => {
	const relativeDate = getRelativeDate(publishedDate);
	const status = getStatus(publishedDate, firstPublishedDate);

	return isRecent(relativeDate) ? (
		<div>
			{status ? <span>{`${status} `} </span> : null}
			<time datetime="{dateformat(publishedDate," data-o-date-format="time-ago-limit-4-hours" data-o-component="o-date">
				{/* Let o-date handle anything &lt; 1 hour on the client */}
				{status ? '' : displayTime(relativeDate)}
			</time>
		</div>
	) : null;
};
github fbsamples / typefast / client / src / js / components / TypeFastLogWindow.js View on Github external
getTimebox(entry: LogEntry): Element {
    const time = dateformat(new Date(entry.time), 'HH:MM:ss.l');
    return (
      <div style="{[styles.time_box]}">{`[${time}]`}</div>
    );
  }
github iota-tangle-io / dtlg / frontend / js / comps / ConfirmationRateChart.tsx View on Github external
tooltipFormat = (val) => {
        return dateformat(new Date(val), 'dd.mm.yy HH:MM:ss')
    }
github OperationCode / operationcode_frontend / src / scenes / home / scholarshipApplication / head / head.js View on Github external
render() {
    return (
      <div>
        <h3> {this.props.scholarship.name} </h3>
        <p> {this.props.scholarship.description} </p>
        <p> {this.props.scholarship.location} </p>
        <p>Apply by {dateFormat(this.props.scholarship.close_time, 'fullDate')} </p>
      </div>
    );
  }
}
github iota-tangle-io / dtlg / frontend / js / comps / TPSChart.tsx View on Github external
tooltipFormat = (val) => {
        return dateformat(new Date(val), 'dd.mm.yy HH:MM:ss')
    }
    tooltipValFormat = (val) => {

dateformat

A node.js package for Steven Levithan's excellent dateFormat() function.

MIT
Latest version published 2 years ago

Package Health Score

80 / 100
Full package analysis

Popular dateformat functions