Socket
Socket
Sign inDemoInstall

timestamp-conv

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    timestamp-conv

Discord Timestamp Converter


Version published
Weekly downloads
64
increased by3.23%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Timestamp Converter

A simple converter designed for DiscordJS timestamps.

npm npm GitHub last commit GitHub FOSSA Status

NPM

Sometimes for some reasons module moment doesn't work properly with discord.js timestamps, so if you have some issues, this module is for you.


date

Simple-Date | date(Number, {forceTimezone: Boolean, timezone: Number}?)
Converts unix timestamp to human date.

getDayOfWeek() Returns day of the week.

getDay() Returns day of the month.

getMonth() Returns month.

getYear() Returns year.

getHour() Returns hours.

getMinute() Returns minutes.

getSeconds() Returns seconds.

getMilliseconds() Returns milliseconds.

getDaysInMonth() Returns days in the month.

formatDay Returns formatted human time in: DD.MM.YYYY.

formatHour Returns formatted human time in: DD.MM.YYYY, hh:mm.

formatSeconds Returns formatted human time in: DD.MM.YYYY, hh:mm:ss.


timestamp

Timestamp-Convert | timestamp(Date | String, {forceTimezone: Boolean, timezone: Number}?)
Converts timestamp to human date.
This class can convert DiscordJS timestamps.

getDayOfWeek() Returns day of the week.

getDay() Returns day of the month.

getMonth() Returns month.

getYear() Returns year.

getHour() Returns hours.

getMinute() Returns minutes.

getSeconds() Returns seconds.

getMilliseconds() Returns milliseconds.

getDaysInMonth() Returns days in the month.

getTimestamp Returns timestamp.

formatDay Returns formatted human time in: DD.MM.YYYY.

formatHour Returns formatted human time in: DD.MM.YYYY, hh:mm.

formatSeconds Returns formatted human time in: DD.MM.YYYY, hh:mm:ss.


Examples:

date() example
// import module
const Converter = require('timestamp-conv');

// set date to: 1608076029
const Date = new Converter.date(1608076029);

console.log(Date.getDay());
// returns day of the month (in UTC 15)

console.log(`${Date.getDay()}.${Date.getMonth()}.${Date.getYear()}, ${Date.getHour()}:${Date.getMinute()}`);
// returns: 15.12.2020, 11:47

console.log(Date.formatDay);
// returns: 15.12.2020
timestamp() example
// import module
const Converter = require('timestamp-conv');

// set date to: Tue, 15 Dec 2020 23:30:24 UTC
const Date = new Converter.timestamp('Tue, 15 Dec 2020 23:30:24 UTC');

console.log(Date.getDay());
// returns day of the month (15)

console.log(`${Date.getDay()}.${Date.getMonth()}.${Date.getYear()}, ${Date.getHour()}:${Date.getMinute()}`);
// returns: 15.12.2020, 23:30

console.log(Date.formatDay);
// returns: 15.12.2020
timestamp() example with forceTimezone
// import module
const Converter = require('timestamp-conv');

// set date to: 2020-07-03T14:28:13.955Z and force timezone to UTC+1
const Date = new Converter.timestamp('2020-07-03T14:28:13.955Z', {forceTimezone: true, timezone: 1});

console.log(Date.getDay());
// returns day of the month (03)

console.log(`${Date.getDay()}.${Date.getMonth()}.${Date.getYear()}, ${Date.getHour()}:${Date.getMinute()}`);
// returns: 03.07.2020, 15:28 (in UTC: 03.07.2020, 14:28)

console.log(Date.formatDay);
// returns: 03.07.2020
timestamp() example with DiscordJS
const Converter = require('timestamp-conv');
const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
    console.log('ready');
});

client.on('message', async (message) => {
    if(message.content === '!creationDate'){
        message.reply(`Your creation date is: ${new Converter.timestamp(message.author.createdAt).formatHour}`);
    }
});

client.login('token');

Keywords

FAQs

Last updated on 20 Apr 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc