Python | Pandas Timestamp.ctime

Python Methods and Functions

The Pandas Timestamp.ctime() function returns the time in string format. The format of the returned string object is based on the ctime () style.

Syntax: Timestamp.ctime ()

Parameters: None

Return: time

Example # 1: Use the Timestamp.ctime ( ) to return the time of this Timestamp in string format.

Output:

We will now use the Timestamp.ctime () function to return the time in string format.

# import pandas as pd

import pandas as pd

 
# Create Timestamp object

ts = pd.Timestamp (year = 2011 , month = 11 , day = 21 ,

hour = 10 , second = 49 , tz = 'US / Central' )

  
# Print the Timestamp object

print (ts)

# return ctime () style time
ts.ctime ()

Output:

As we can see in the output, the Timestamp.ctime () function returned the time of the given Timestamp object in string format.

Example # 2: Use the Timestamp function. ctime () to return the time of the given Timestamp in string format.

# import pandas as pd

import pandas as pd

 
# Create Timestamp object

ts = pd.Timestamp (year = 2009 , month = 5 , day = 31 ,

hour = 4 , second = 49 , tz = 'Europe / Berlin' )

 
# Print Timestamp object

print (ts)

Output:

We will now use the Timestamp.ctime () function to return the time in string format.

# return time in ctime () style
ts.ctime ()

Output:

As we can see in the output, the Timestamp.ctime () function returned the time of the given Timestamp object in string format.





Get Solution for free from DataCamp guru