
- LISP Tutorial
- LISP - Home
- LISP - Overview
- LISP - Environment
- LISP - REPL
- LISP - Program Structure
- LISP - Basic Syntax
- LISP - Data Types
- Lisp Macros
- LISP - Macros
- LISP - Backquote and Comma
- LISP - Code Generation Using Macro
- LISP - Variable Capture and Hygienic macro
- LISP - Scope and Binding
- LISP - Macro Writing Style
- LISP - Macro Characters
- LISP - Read-Time Macros
- LISP - Compiler Macros
- LISP - Uses of Macros
- Lisp Functions
- LISP - Functions
- LISP - Functions vs Macros
- LISP - Calling Function using funcall
- LISP - Calling Function using apply
- LISP - Closures
- LISP - Functions as Arguments
- LISP - Functions as Return Values
- LISP - Recursion
- LISP - Built-in Functions
- Lisp Predicates
- LISP - Predicates
- LISP - Generic Data Type Predicates
- LISP - Specific Data Type Predicates
- LISP - Equality Predicates
- LISP - Numeric Predicates
- LISP - Comparison Predicates
- LISP - Logical Predicates
- LISP - List Predicates
- LISP - Custom Predicates
- LISP - Chaining Predicates
- Lisp Arrays
- LISP - Arrays
- LISP - Adjustable Arrays
- LISP - Fill Pointers in Arrays
- LISP - Specialized Arrays
- LISP - Arrays Properties
- LISP - Iterating over Arrays
- LISP - Multidimensional Arrays
- LISP - Row-Major Order
- Lisp Strings
- LISP - Strings
- LISP - String Concatenation
- LISP - String Comparison
- LISP - String Case Conversion
- LISP - String Trimmimg
- LISP - String Searching
- LISP - Getting Substring
- LISP - String Replacement
- LISP - Sorting Strings
- LISP - Merging Strings
- LISP - Accessing Characters of String
- LISP - String length
- LISP - Escape Sequences
- Lisp Sequences
- LISP - Sequences
- LISP - Accessing Element of Sequence
- LISP - Sequence length
- LISP - Getting Subsequence
- LISP - Search Element in Sequence
- LISP - Sequence Concatenation
- LISP - Reversing a Sequence
- LISP - Mapping Sequence Element
- LISP - position of Element
- LISP - Remove an Element
- LISP - Sort Sequence
- LISP - Merge Sequences
- LISP - every function
- LISP - some function
- LISP - notany function
- LISP - notevery function
- Lisp Lists
- LISP - Lists
- LISP - Accessing Elements of Lists
- LISP - Modifications to Lists
- LISP - Using mapcar on List
- LISP - Using mapc on List
- LISP - Using reduce on List
- LISP - Removing elements from List
- LISP - Reversing a List
- LISP - Sorting a List
- LISP - Searching a List
- LISP - List vs Vectors
- LISP - Matrix Multiplication
- Lisp Vectors
- LISP - Vectors
- LISP - Creating Vectors
- LISP - Accessing Elements of Vectors
- LISP - Modifications to Vectors
- LISP - Adjustable Vectors
- LISP - Specialized Vectors
- LISP - Vector Functions
- Lisp Set
- LISP - Set
- LISP - Adding elements to the Set
- LISP - Getting SubSet from a Set
- LISP - Set Difference
- LISP - Set Exclusive OR
- LISP - Set Intersection
- LISP - Set Union
- LISP - Representing Set with HashTable
- LISP - List as Set vs HashTable as Set
- Lisp Tree
- LISP - Tree
- LISP - Recursive Traversal
- LISP - Inorder Traversal
- LISP - Preorder Traversal
- LISP - Postorder Traversal
- LISP - Depth First Traversal
- LISP - Modifying Tree
- LISP - Search Tree
- LISP - Binary Tree
- Lisp Hash Table
- LISP - Hash Table
- Adding Values to Hash Table
- Removing Values from Hash Table
- Updating Values of Hash Table
- Iterating Hash Table Entries
- Searching key in HashTable
- Checking Size of HashTable
- Using Custom Equality Check
- Lisp - Input − Output
- LISP - Input − Output
- LISP - Streams
- LISP - Reading Data from Streams
- LISP - Writing Data to Streams
- LISP - File I/O
- LISP - String I/O
- LISP - Formatting with Format
- LISP - Interactive I/O
- LISP - Error Handling
- LISP - Binary I/O
- Lisp - Structures
- LISP - Structures
- LISP - Accessors and Mutators
- LISP - Structure Options
- LISP - Structure Types
- LISP - Applications and Best Practices
- Lisp - CLOS
- LISP - CLOS
- Lisp - Objects
- LISP - Class
- LISP - Slots and Accessors
- LISP - Generic Functions
- LISP - Class Precedence
- LISP - Metaobject Protocol
- LISP - Multimethods
- LISP - Multiple Inheritance
- LISP - Method Combinations
- LISP - Method Combinations
- LISP - :before Method Combination
- LISP - :primary Method Combination
- LISP - :after Method Combination
- LISP - :around Method Combination
- LISP - + Method Combination
- LISP - and Method Combination
- LISP - append Method Combination
- LISP Useful Resources
- Lisp - Quick Guide
- Lisp - Useful Resources
- Lisp - Discussion
Lisp - Handling Date & Time
In Lisp, we can handle date and time using builtin functions and using external libraries for more advanced operations on date and time.
Built-in Functions
Following are some of the important built-in functions in Common Lisp to work with date and time.
get-universal-time function is used to get the current date time as a UTC time, number of seconds elapsed since January 1, 1900, 00:00:00 GMT.
decode-universal-timefunction is used to converts a universal time into a decoded time, which is in form of a tuple of nine values. Each value represents seconds, minutes, hours, day, month, year, day of the week (0=Monday to 6=Sunday), daylight saving time flag (T or NIL), and time zone (hours west of GMT).
encode-universal-time function does reverse of decode-universal-time and is used to convert a decoded time back into a universal time.
get-decoded-timefunction is equivalent to (decode-universal-time (get-universal-time))) and returns the current time as a decoded time.
get-internal-real-time function is used for internal purpose and returns the current real time in implementation-dependent units.
get-internal-run-time function is used to get the current run time of the Lisp process in implementation-dependent units.
internal-time-units-per-second holds the number of internal time units in one second for the current Lisp implementation.
Usage of Universal Time
get-universal-time returns the time in number of seconds.
main.lisp
(print (get-universal-time))
Output
When you execute the code, it returns the following result −
3955268890
Decode Universal Time
decode-universal-time can be used to get parse universal time as shown below −
main.lisp
(multiple-value-bind (second minute hour day month year day-of-week dst-flag time-zone) (decode-universal-time (get-universal-time)) (format t "Time ~2,'0d:~2,'0d:~2,'0d on ~A, ~d/~d/~d (GMT~@d)" hour minute second (case day-of-week (0 "Mon") (1 "Tue") (2 "Wed") (3 "Thu") (4 "Fri") (5 "Sat") (6 "Sun")) day month year time-zone))
Output
When you execute the code, it returns the following result −
Time 19:20:34 on Sat, 3/5/2025 (GMT-11/2)
Where −
Seconds − Represents second of the minute (0-59). In the example above, it's 34.
Minutes − Represents minute of the hour (0-59). In the example, it's 20.
Hours − Represents hour of the day (0-23). In the example, it's 19.
Day − Represents day of the month (1-31). In the example, it's 3.
Month − Represents month of the year (1-12). In the example, it's 5 (May).
Year − Represents the year. In the example, it's 2025.
Day of the Week − represented by an integer as the day of the week, where 0 is Monday and 6 is Sunday. In the example, 3 corresponds to Saturday.
Daylight Saving Time Flag − is a boolean value. It is t where day light savings is applicable. In the example, it's NIL.
Time Zone − It represents the difference in hours between the local time zone and Greenwich Mean Time, GMT. For Delhi, which is typically GMT+5:30. In the example, it is 11/2.
External Libraries
We can import external libraries for comprehensive coverage on date time operations. Following are some of the popular libraries for Common Lisp.
local-time − It is the most popular external library for date time manipulation. It provide a rich set of functionalities including timezone handling, date and time arithmetic, conversion between universal time, unix time and timestamps and lots more.
cl-dates − It is mainly used in business and financial applications for its execellent date manipulation abilities. It supports date formatting, date arithmetic, calculating date differences and so on.
simple-date-time − It is a simple date time library providing basic date and time handling.
cl-date-time-parser − It is specific to convert date in various formats to universal time.