Hard Written By Jaguar515_YT

Understanding os.date Created on: 26-12-2019

A guide to using os.date

os.date is a built-in function that returns a table containing information about the current year, day, etc.

There are two arguments to os.date - a format string and the time. Let's go over the arguments. The format string is used to format in two ways - UTC (Universal Time Coordinated) or the local time (for example, if you live in New York City it would return the current day in New York City).

These can be expressed with either "!t" (UTC time) and "t" (local time) respectively.

The time is basicially straightforward - it's just os.time().

Inside the table, there are a couple contents inside the table, such as, but not limited to:

  • Current year
  • Current day
  • Current second

Here's an example below:

-- This returns the current month, day and year
local date = os.date("*t", os.time())
 -- Notice how this will return the local time that you are living in, not UTC time.

-- Table for months and weekdays
local months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
local days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}

-- Output the current day, month and year
print("Today is "..days[date.wday]..", "..months[date.month].." "..date.day.." "..date.year)
-- Example output: Today is Thursday, December 26 2019

Anyways, that concludes this little tutorial. There's more info at

https://developer.roblox.com/en-us/api-reference/lua-docs/os

if you want to learn more about os and os.date.

Hard Written By Jaguar515_YT

See Jaguar515_YT's profile on Roblox

Discussion