![jumpstorydownload20200403000422 | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/jumpstory-download20200403-000422.jpg?resize=1140%2C694&ssl=1)
We know how to manipulate Date Time in our Delphi/C++ Builder with n-number of APIs in TDateTime. Similarly, Python’s standard library and some other low-level modules have a near-complete date, time, and timezone functionality, but don’t work very well from a usability perspective like too many Modules and types, timezone, and timestamp conversions are verbose. To fill these gaps of usability perspective an Excellent powerful library Arrow is built. In this post will get to understand how to use Arrow using Python4Delphi in Python GUI Delphi/C++ applications.
Prerequisites.
- If not python and Python4Delphi is not installed on your machine, Check this how to run a simple python script in Delphi application using Python4Delphi sample app
- Open windows open command prompt, and type pip install -U arrow to install arrow. For more info for Installing Python Modules check here
- First, run the Demo1 project for executing Python script in Python for Delphi. Then load the script in the Memo1 field and press the Execute Script button to see the result. Go to GitHub to download the Demo1 source.
Arrow Python Library sample script details: The sample script demonstrates,
- How the Date time is created in different ways i.e using now(), from timestamps, using a naive or time-aware DateTime
- Using properties to represent the date time and Formatting the date-time
- Replace and shift the date-time for the user’s preferred date-time value.
- Convert from one timezone to others by name or tzinfo.
- Humanize the DateTime relative to now.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import arrow from dateutil import tz from datetime import datetime #Creation using Get 'now' easily print(arrow.utcnow()) print(arrow.now()) print(arrow.now('US/Pacific')) #Creation from timestamps print(arrow.get(1367900664)) print(arrow.get(1367900664.152325)) #Cretion Using a naive or timezone-aware datetime, or flexibly specify a timezone: print(arrow.get(datetime.utcnow())) print(arrow.get(datetime(2013, 5, 5), 'US/Pacific')) print(arrow.get(datetime(2013, 5, 5), tz.gettz('US/Pacific'))) print(arrow.get(datetime.now(tz.gettz('US/Pacific')))) #Get datetime nad timestamp representation a = arrow.utcnow() print(a.datetime) print(a.timestamp) #Get a naive datetime, and tzinfo print(a.naive) print(a.tzinfo) #Get datetime functions. print(a.year) print(a.date()) print(a.time()) #Replace and shift print(a) print(a.replace(hour=4, minute=40)) print(a.shift(weeks=+3)) print(a.replace(tzinfo='US/Pacific')) #Formatting print(arrow.utcnow().format('YYYY-MM-DD HH:mm:ss ZZ')) #Convert from UTC to other timezones by name or tzinfo utc = arrow.utcnow() utc print(utc.to('US/Pacific')) print(utc.to(tz.gettz('US/Pacific'))) #Humanize relative to now past = arrow.utcnow().shift(hours=-1) print(past.humanize()) present = arrow.utcnow() future = present.shift(hours=2) print(future.humanize(present)) #Get the time span of any unit: print(arrow.utcnow().span('hour')) #Just get the floor and ceiling: print(arrow.utcnow().floor('hour')) print(arrow.utcnow().ceil('hour')) |
![ArrowDemo8988923 | Embarcadero RAD Studio Delphi C++Builder Blogs arrowdemo 8988923](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/ArrowDemo-8988923.png?resize=750%2C405&ssl=1)
Note: Samples used for demonstration were picked from here with only the difference of printing the outputs. You can check the APIs and some more samples from the same place.
You have read the quick overview of Arrow library, download this library from here and use user-friendly Date Time manipulations in your applications. Check out Python4Delphi and easily build Python GUIs for Windows using Delphi.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition