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

localnow

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

localnow

Drop-in replacement for `datetime.datetime.now()` explicitly set with the local timezone.

  • 0.1.0
  • PyPI
  • Socket score

Maintainers
1

localnow

Description

This small Python package is a drop-in replacement for datetime.datetime.now that returns the current time in the local timezone.

Usage

Suppose you want the current date and time. You could do this:

import datetime

x = datetime.datetime.now()

By default, x will be in UTC. datetime.datetime.now takes an optional tz argument that you can use to specify a different timezone. However, if you want to use your local timezone, wherever that may be, you need an extra step:

import datetime

tz = datetime.datetime.utcnow().astimezone().tzinfo
x = datetime.datetime.now(tz=tz)

Personally, I find the tz = ... line to be a bit of a distraction and difficult to remember, so I made this package. It provides a drop-in replacement for datetime.datetime.now that is essentially does the same as the code above but with a little less code:

from localnow import now

x = now()

That's it.

Installation

You can install this package from PyPI:

pip install localnow

License

MIT

Keywords

FAQs


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