---
title: "How to get the current time?"  
description: "How to get the current time?"  
author: "Utpal Vishwas"  
published: 2023-07-17  
updated: 2023-07-20  
canonical: https://answers.mindstick.com/qa/100269/how-to-get-the-current-time  
category: "troubleshoot"  
tags: ["time", "date filters"]  
reading_time: 2 minutes  

---

# How to get the current time?

How to get the current time?

## Answers

### Answer by Yashna Bawa

There are several ways to get the current time. Here are the most common methods:

![How to get the current time?](https://answers.mindstick.com/questionanswer/de014cad-9c00-48f1-a3be-c82142907d08/images/30f3050a-bb97-45b9-aba2-c642df8bc846.png)

**Using the** `time` **command**

The `time` command is a built-in command that can be used to get the current time. To use the `time` command, open a terminal window and type the following [command](https://www.mindstick.com/articles/332288/complete-overview-on-linux-awk-command):

time

This will print the current time to the terminal window.

**Using the** `date` **command**

The `date` command is another built-in command that can be used to get the current time. To use the `date` command, open a terminal window and type the following command:

date\

This will print the current time and date to the terminal window.

**Using the** `now()` **function**

The `now()` function is a built-in function that can be used to get the current time. To use the `now()` function, you will need to import the `datetime` module.

Python

import datetime\
\
now = datetime.datetime.now()\
\
print(now)\
Use code with caution.

This will print the current time to the console.

## Using a third-party library

There are also a number of third-party libraries that you can use to get the current time. These libraries offer features that the built-in commands and [functions](https://www.mindstick.com/interview/23273/explain-the-use-of-command-objects) do not, such as the ability to get the current time in different time zones.

Here are some popular third-party libraries for getting the current time:

- **Pendulum:** Pendulum is a powerful library that offers a wide range of features. It is a paid library, but it offers a free trial.

- **Arrow:** Arrow is a lightweight library that is easy to use. It is a free library.

- **Moment:** Moment is a popular library that offers a good balance of features and ease of use. It is a free library.

## Tips for getting the current time

Here are some tips for getting the current time:

- **Use the** `time` **or** `date` **command:** These are the simplest ways to get the current time.
- **Use the** `now()` **function:** This is a more flexible way to get the current time.
- **Use a third-party library:** If you need more features, you can use a third-party library.
- **Format the time correctly:** Make sure that you format the time correctly so that you can use it in your code.


---

Original Source: https://answers.mindstick.com/qa/100269/how-to-get-the-current-time

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
