Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

datetime-locale

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datetime-locale

Converts javascript dates to/from values used for input[type=datetime-locale]

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

datetime-locale

Formats dates so that they can be used on <input type="datetime-locale"> elements. Particularly useful when working with libraries like React to bind value states. The format necessary is described in detail in the MDN docs.

Works on both the client and server, but should really only be used on the client since these strings do not contain timezone information. If you send these to the server and your users are in a different timezone then you may be in a whole lot of trouble.

Usage

Convert a date to datetime-locale compatible string

const datetimeLocale = require('datetime-locale')
console.log(datetimeLocale.toString(new Date()));
// 2020-01-06T10:33:38

Convert an input value into a javascript date

const datetimeLocale = require('datetime-locale');
const localeString = document.getElementById("dateInput").value;
console.log(datetimeLocale.fromString(localeString));
// Mon Jan 06 2020 10:33:38 GMT-0800 (Pacific Standard Time)

Example usage with React

import datetimeLocale from 'datetime-locale';


const ControlledDateTimeInput = () => {
  const [date, setDate] = useState(new Date());
  
  const handleInputChange = (e) => {
    setDate(datetimeLocale.fromString(e.target.value));
  }

  return <input type="datetime-locale" value={datetimeLocale.toString(date)} />

}

Keywords

FAQs

Package last updated on 06 Jan 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc