VOOZH about

URL: https://www.geeksforgeeks.org/python/arrow-module-in-python/

⇱ Arrow module in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Arrow module in Python

Last Updated : 28 Apr, 2025

Arrow is a Python module for working with date and time. It offers a sensible and human-friendly approach to creating, manipulating, formatting and converting dates, times and timestamps. It allows easy creation of date and time instances with timezone awareness. 
 

Installation

The arrow module is installed with the following command: 
 

pip install arrow


 

Features 

  • User friendly.
  • Timezone-aware and UTC by default.
  • Timezone conversion.
  • Time frame ranging from microsecond to year.
  • Easy to use.
  • Formats and parses strings automatically.
  • Supports a growing list of contributed locales.


 

Getting UTC (Universal Time Coordinated) time.


In order to get current UTC time we use utcnow() method.
 

Output : 
 

Current UTC Time is = 2020-02-28T18:06:39.228924+00:00


 

Getting Indian time.


In order to get current regional(Indian) time we use now() method.
 

Output : 
 

Current India Time = 2020-02-28T23:40:07.112695+05:30

Parsing string to date


In order to parse the string into date format we use get() method.
 

Output : 
 

2020-02-02T12:30:45+00:00

Unix time


Unix time is a system for describing a point in time. It is the number of seconds that have elapsed since the Unix epoch, that is the time 00:00:00 UTC on 1 January 1970, minus leap seconds. 
 

  • timestamp() method is used to get unix time. 
     
  • fromtimestamp() method used to convert the Unix time back to the arrow date object. 
     

Output : 
 

2020-03-04T13:33:15.041536+00:00
1583328795
2020-03-04T19:03:15+05:30

Arrow instance from datetime


An instance of the arrow module can also be created from the DateTime module. Consider the below example for a better understanding of the topic.
 

Output : 
 

2020-03-04 19:16:04.317690
2020-03-04T00:00:00+00:00

Properties for getting individual datetime objects


if you want to get any object as an individual, here are some properties that can be used.
 

Output : 
 

datetime.time(19, 16, 04, 317690)
datetime.date(2020, 3, 4)
2020

Replace and Shift property


if you want to replace or shift any object as an individual, here are some properties that can be used.
 

Output : 
 

without alteration: 2020-03-04T13:33:15.041536+00:00
with hours and minutes replaced: 2020-03-04T05:30:15.041536+00:00
with weeks shifted 3 forward: 2020-03-25T13:33:15.041536+00:00
with timezone replaced: 2020-03-04T13:33:15.041536-07:00 

Humanized format


All the above properties and function outputs are more of a computer format but what if you wanted it to be more of a human form? for example: "an hour ago" or "2 hours ago",here are some properties that can be used to achieve humanized format.
 

Output : 
 

'an hour ago'
'in 3 hours'
'in 73 minutes'
'in an hour and 13 minutes'


 

Comment
Article Tags: