Small selection of functions relating to date and time.
Functions
get_timestamp
Use the following to get the current timestamp and its formatted version.
--- Utils object
local timestamp = utils.dates.get_timestamp().timestamp
local formatted_timestamp = utils.dates.get_timestamp().formatted
print('Timestamp:', timestamp)
print('Formatted Timestamp:', formatted_timestamp)
--- Direct export
local timestamp = exports.boii_utils:get_timestamp().timestamp
local formatted_timestamp = exports.boii_utils:get_timestamp().formatted
convert_timestamp
Use the following to convert a UNIX timestamp to a human readable date and time format.
--- Retrieve the current timestamp
local timestamp = utils.dates.convert_timestamp().timestamp
--- Utils object
local converted_date = utils.dates.convert_timestamp(timestamp).date
local converted_time = utils.dates.convert_timestamp(timestamp).time
local converted_formatted = utils.dates.convert_timestamp(timestamp).formatted
--- Direct export
local converted_date = exports.boii_utils:convert_timestamp(timestamp).date
local converted_time = exports.boii_utils:convert_timestamp(timestamp).time
local converted_formatted = exports.boii_utils:convert_timestamp(timestamp).formatted
get_current_date_time
Use the following to retrieve the current date and time.
--- Utils object
local date = utils.dates.get_current_date_time().date
local time = utils.dates.get_current_date_time().time
local formatted = utils.dates.get_current_date_time().formatted
--- Direct export
local date = exports.boii_utils:get_current_date_time().date
local time = exports.boii_utils:get_current_date_time().time
local formatted = exports.boii_utils:get_current_date_time().formatted
add_days_to_date
Use the following to add a number of days to a given date.
--- Retrieve date
local date = utils.dates.get_current_date_time().date
--- Specify days to add
local days = 3
--- Utils object
local new_date = utils.dates.add_days_to_date(date, days)
--- Direct export
local new_date = exports.boii_utils:add_days_to_date(date, days)
date_difference
Use the following to calculate the difference between two dates.
--- Retrieve date
local date = utils.dates.get_current_date_time().date
--- Specify days to add
local days = 3
--- Specify new date *using add_days_to_date for example*
local new_date = utils.dates.add_days_to_date(date, days)
--- Utils object
local date_difference = utils.dates.date_difference(date, new_date)
print('Date Difference:', date_difference')
--- Direct export
local date_difference = exports.boii_utils:date_difference(date, new_date)
convert_timestamp_ms
Use the following to convert a UNIX timestamp in milliseconds to a human readable date-time format.
--- Specify/retrieve timestamp
local timestamp = 1628759592000
--- Utils object
local date = utils.dates.convert_timestamp_ms(timestamp).date
local time = utils.dates.convert_timestamp_ms(timestamp).time
local formatted = utils.dates.convert_timestamp_ms(timestamp).formatted
--- Direct export
local date = exports.boii_utils:convert_timestamp_ms(timestamp).date
local time = exports.boii_utils:convert_timestamp_ms(timestamp).time
local formatted = exports.boii_utils:convert_timestamp_ms(timestamp).formatted
timestamp_difference_ms
Use the following to calculate the difference between two timestamps.
--- Specify/retrieve timestamp 1
local timestamp_1 = 1628759592000
--- Specify/retrieve timestamp 2
local timestamp_2 = 628759592000
--- Utils object
local difference = utils.dates.timestamp_difference_ms(timestamp_1, timestamp_2)
--- Direct export
local difference = exports.boii_utils:timestamp_difference_ms(timestamp_1, timestamp_2)