Skip to content

Sakthiganesan91/datetimesaga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Date Formatter Package

A simple JavaScript package for formatting the current date into a structured object containing the day, month, and year, with support for localization options.

Installation

You can install the package via npm. Run the following command in your project directory:

npm install datetimesaga

Usage

import getDate from 'datetimesaga';

const today = getDate();
console.log(today);
// Output: { date: 10, month: 'September', year: '2024', day: 'Tuesday' }

import { getTime } from 'datetimesaga';

// Get time in 'en-US' locale with medium style
const time = getTime({ locales: 'en-US', timeStyle: 'medium' });
console.log(time);
// Output: "3:45:30 PM"

// Get time in 'fr-FR' locale with short style
const timeInFrench = getTime({ locales: 'fr-FR', timeStyle: 'short' });
console.log(timeInFrench);
// Output: "15:45"

API

getDate(options)

This function returns an object with the current date, month, year, and day.

Parameters:
options (Object): An optional object to customize the output.
locales (string): A string with a BCP 47 language tag (default: "en-US").
monthFormat (string): The format for the month (default: "long").
Options include "numeric", "2-digit", "long", "short", "narrow".
weekDayFormat (string): The format for the weekday (default: "long").
Options include "narrow", "short", "long".
yearFormat (string): The format for the year (default: "numeric").
Options include "numeric", "2-digit".

Returns:

An object containing:
date: The current date (number).
month: The formatted month (string).
year: The formatted year (string).
day: The formatted day of the week (string).

getTime(options)


This function returns the current time as a formatted string, based on the provided locale and formatting options.
Parameters: options (Object): An optional object to customize the output.
locales (string): A string with a BCP 47 language tag (default: "en-US").
timeStyle (string): The format for the time (default: "medium").
Options include "full", "long", "medium", "short".

Returns:

A formatted string representing the current time. If an error occurs, the function returns "N/A".

About

package for formatting Date and Time

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published