npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

carbondate

v2.1.12

Published

A Simple DateTime Package Based On dayjs. Also Supports Timezone. Developer friendly syntax.

Downloads

25

Readme

carbondate

A simple DateTime Package based on dayjs. Also supports timezone. Developer friendly syntax.

Installation

npm i carbondate

Uses

import this in your project

import CarbonDate from "carbondate";

Or

const CarbonDate = require('carbondate');

Initialization

CarbonDate.init().now().format().value;
// 2024-05-27 13:09:59

Or

const datetime = new CarbonDate();
datetime.now().format().value;
// 2024-05-27 13:09:59

Or

CarbonDate.init().createFromObject({year: new Date().getFullYear(), month: (new Date().getMonth() + 1), day: new Date().getDate(), hour: '00', minute: '00', second: '00'}).toDateTimeString().value
// 2024-10-22 00:00:00

Getters

CarbonDate.init().getYear().value
// 24

Fluent Setters

CarbonDate.init().setYear(2001).setMonth(12).setDay(12).setHour(11).setMinute(45).setSecond(50).toDateTimeString().value
// 2001-12-12 11:45:50

List of all available formats

CarbonDate.init().now().format('YYYY-MM-DD hh:mm:ss A').value
// 2024-05-27 02:06:21 PM

Parsing

CarbonDate.init().parse(new Date()).format().value
// 2024-05-27 13:10:11

Or

CarbonDate.init().parse(CarbonDate.init().now().value).format().value
// 2024-05-27 13:10:20

Or

CarbonDate.init().parse('2022').format().value
// 2022-01-01 00:00:00

Or

CarbonDate.init().parse('2022-05').format().value
// 2022-05-01 00:00:00

Or

CarbonDate.init().parse('2022-05-08').format().value
// 2022-05-08 00:00:00

Or

CarbonDate.init().parse('10:55:10').format().value
// 2024-05-27 10:55:10

Or

CarbonDate.init().parse('20:55:10').format('YYYY-MM-DD hh:mm:ss A').value
// 2024-05-27 08:55:10 PM

Or

CarbonDate.init().parse('2023-05-04 20:55:10').format('YYYY-MM-DD hh:mm:ss A').value
// 2023-05-04 08:55:10 PM

String Formatting

CarbonDate.init().now().toDateTimeString().value
// 2024-10-18 04:33:07

Addition

Add One Day

CarbonDate.init().now().addDay().format().value
// 2024-05-28 13:19:59

Add More than one Day

CarbonDate.init().now().addDays(2).format().value
// 2024-05-29 13:20:50

List of all methods

Subtract

Subtract One Day

CarbonDate.init().now().subDay().format().value
// 2024-05-26 13:19:59

Subtract More than one Day

CarbonDate.init().now().subDays(2).format().value
// 2024-05-25 13:20:50

List of all methods

Difference

Difference in day between two days

CarbonDate.init().now().diffInDays(CarbonDate.init().now().subDay().value).value
// 1

OR

CarbonDate.init().parse('2024-05-01').diffInDays(CarbonDate.init().parse('2024-05-05').value).value
// 4

List of all methods

Comparison

Comparing two dates

CarbonDate.init().parse('2024-05-01').lessThan(CarbonDate.init().parse('2024-05-05').value).value
// true

OR

CarbonDate.init().now().lessThan(CarbonDate.init().parse('2024-05-05').value).value
// false

List of all methods

Constants

CarbonDate.init().SUNDAY
// 0

OR

let instance = new CarbonDate();
instance.SUNDAY
// 0

Common Functions

CarbonDate.init().yesterday().toDateTimeString().value
// 2024-10-21 04:30:05

Leap Year

CarbonDate.init().yesterday().checkLeapYear().value
// true

Days in month

CarbonDate.init().now().dayCountInMonth().value
// as now is May so output is: 31

Start of month

CarbonDate.init().now().startOfMonth().format('YYYY-MM-DD').value
// 2024-05-01

End of month

CarbonDate.init().now().endOfMonth().format('YYYY-MM-DD').value
// 2024-05-31

Diff for human

CarbonDate.init().now().diffForHumans().value
// a few seconds ago

Or

CarbonDate.init().now().diffForHumans(CarbonDate.init().now().subHour().value).value
// in an hour

Month Number

  • be careful with the month name spelling
CarbonDate.init().monthNumber('January').value
// 01

OR

CarbonDate.init().monthNumber('jan').value
// 01

dayOfYear

  • get date from day number
CarbonDate.init().now().dateFromDayNumber(300).format('YYYY-MM-DD HH:mm:ss').value
// 2024-10-26 21:20:30

OR

CarbonDate.init().parse('2024-09-05').dateFromDayNumber(300).format('YYYY-MM-DD HH:mm:ss').value
// 2024-10-26 21:20:30
  • get day number of year
CarbonDate.init().now().dayNumberOfYear().value
// as now is 09-12-2024 output is: 344

OR

CarbonDate.init().parse('2024-09-05').dayNumberOfYear().value
// 249

Timezone

List of all available timezones.

Set your own Timezone

CarbonDate.init('America/Los_Angeles').now().format().value;
// 2024-05-28 06:12:26

Or

const datetime = new CarbonDate('America/Los_Angeles');
datetime.now().format().value;
// 2024-05-28 06:12:26

if you are not using any timezone. then it will take system timezone by default.

if you wish to use .env file for timezone; for central timezone for your app

  1. Install dotenv package. using npm i dotenv
  2. Create .env file to the root of your project
  3. set timezone APP_TIMEZONE='America/Los_Angeles'

After following this steps you can use like the example bellow:

CarbonDate.init().now().format().value;
// 2024-05-28 06:12:26 this is the time for America/Los_Angeles

Or

const datetime = new CarbonDate();
datetime.now().format().value;
// 2024-05-28 06:12:26 this is the time for America/Los_Angeles

Current Timezone

CarbonDate.init('America/Los_Angeles').currentTimezone().value
// America/Los_Angeles

if you are not using .env file

CarbonDate.init().currentTimezone().value
// Asia/Dhaka my current timezone

Convert date time to a specific timezone

CarbonDate.init('America/Los_Angeles').parse('2024-05-10 10:00:50', true).format('YYYY-MM-DD hh:ss:mm A').value
// 2024-05-09 09:50:00 PM

if you are using .env file

CarbonDate.init().parse('2024-05-10 10:00:50', true).format('YYYY-MM-DD hh:ss:mm A').value
// 2024-05-09 09:50:00 PM