How do I use os.date?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a log history of purchases made by players.
  2. What is the issue? Include screenshots / videos if possible!
    I need to know how to use os.date so I can make the logs say the date and time of purchase from the player.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have looked on the devfroum but it doesnt explain it well.
3 Likes

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

-- September 16th, 1998 at 11:48:10 PM:
local stringToFormat = "Today is %x, which is a %A, and the time is %X."
local timestamp = 906000490
-- The specifiers %x, %A, and %X are replaced with their values in stringToFormat:
local result = os.date(stringToFormat, timestamp)
print(result)
--> Today is 09/16/98, which is a Wednesday, and the time is 22:48:10.

13 Likes

Why do I use % when using os.date?

1 Like

For example if you wanted to get the name of the month you would do

os.date("%B") --I think this is how you do it
2 Likes

Do you know why I would use %?

Because it’s a specifier so the engine knows what to do.

Okay thank you for helping me have a better understanding.

Make sure that what I said is correct i’m not 100% sure.

“%” is an operator. Specifically a modulus, the remainder of one number divided by another.

2 Likes

Yeah it didnt print anything in output… I changed solution to nobody yet.

No, in this case it’s used as a part of a string pattern.

1 Like

Thank you for clearing % up for me.

1 Like

Could you show me a code block example?

Check out DateTime.

local dt = DateTime.now()
print("The date is " .. dt:FormatLocalTime("LL", "en-us"))
2 Likes

did you do

print(os.date("%B"))
2 Likes

No I will try out your solution now.

Thank you so much it worked! Thanks man.

Could you use localization service with this?

This is complicated. More complicated then the forum post on os.date.

I haven’t really researched about localization service yet so I dont understand that service.