Retrieve the Current Date and Time in Python

Cloudmersive
1 min readDec 4, 2020

When creating a website or application, it is important for it to be polished, accurate, and user-friendly. One of the steps you can take in achieving these goals are to ensure your systems are running on the most accurate date and time information, particularly if the service you are offering is time sensitive. The following API will allow you to retrieve the current date and time based on synchronization with atomic clocks to provide consistency for your users.

To use this API, run this command to install the SDK:

pip install cloudmersive-validate-api-client

Then, you can call the function:

from __future__ import print_function
import time
import cloudmersive_validate_api_client
from cloudmersive_validate_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_validate_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_validate_api_client.DateTimeApi(cloudmersive_validate_api_client.ApiClient(configuration))
try:
# Get current date and time as of now
api_response = api_instance.date_time_get_now_simple()
pprint(api_response)
except ApiException as e:
print("Exception when calling DateTimeApi->date_time_get_now_simple: %s\n" % e)

You can retrieve the API Key from the Cloudmersive website at no cost and with no commitment. This will provide you with 800 monthly calls across our library of APIs.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.