Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas
communitycreator

How to obtain the current time in the local timezone in pandas

Onyejiaku Theophilus Chidalu

Overview

To obtain the current time in the local time zone in pandas, we use the now() function of Pandas.Timestamp (an equivalent of Python's datetime object).

Syntax

The now() function takes the following syntax:

Timestamp.now(tz=None)
The syntax for the now() function

Parameter value

The now() function takes a single optional parameter value, tz, which represents the local timezone.

Return value

The now() function returns a Timestamp object showing the current time.

Example

# A code to illustrate the now() function in Pandas
# importing the pandas library
import pandas as pd

# obtaining the current time
print(pd.Timestamp.now())
Implement the now() function

Explanation

  • Line 3: We import the pandas library.
  • Line 6: We use the now() function to obtain the current time and print the value to the console.

RELATED TAGS

pandas
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring