PtokaX forum

Archive => Archived 5.1 boards => HOW-TO's => Topic started by: Herodes on 24 September, 2006, 15:20:24

Title: Clarification of os.date()
Post by: Herodes on 24 September, 2006, 15:20:24
Many of you scripters out there are using the os.date function from the os lib of Lua in PtokaX...
There goes the manual explanation...

Quote from: The 5.1 Lua Manualos.date ( [ format [ , time ] ] )

Returns a string or a table containing date and time, formatted according to the given string format.

If the time argument is present, this is the time to be formatted (see the os.time function for a description of this value). Otherwise, date formats the current time.

If format starts with '!', then the date is formatted in Coordinated Universal Time. After this optional character, if format is the string "*t", then date returns a table with the following fields: year (four digits), month (1--12), day (1--31), hour (0--23), min (0--59), sec (0--61), wday (weekday, Sunday is 1), yday (day of the year), and isdst (daylight saving flag, a boolean).

If format is not "*t", then date returns the date as a string, formatted according to the same rules as the C function strftime.

When called without arguments, date returns a reasonable date and time representation that depends on the host system and on the current locale (that is, os.date() is equivalent to os.date("%c")).

Notice the vague part!

"If format is not "*t", then date returns the date as a string, formatted according to the same rules as the C function strftime."

I was really confused at this part myself when trying to get to know the os.date function,... I was looking for what this func can take,...
and I found it :) there you go the complete proper string formations of os.date():


"%a"The abbreviated weekday name. Example: Thu.
"%A"The full weekday name. Example: Thursday.
"%b"The abbreviated month name. Example: Sep.
"%B"The full month name. Example: September.
"%dThe two-digit day of the month padded with leading zeroes if applicable. Example: 09.
"%e"The day of the month space padded if applicable. Example: 9.
"%H"The two-digit military time hour padded with a zero if applicable. Example: 16.
"%I"The two-digit hour on a 12-hour clock padded with a zero if applicable. Example: 04.
"%j"The three-digit day of the year padded with leading zeroes if applicable. Example: 040.
"%k"The two-digit military time hour padded with a space if applicable. Example: 9.
"%l"The hour on a 12-hour clock padded with a space if applicable. Example: 4.
"%m"The two-digit month padded with a leading zero if applicable. Example: 09.
"%M"The two-digits minute padded with a leading zero if applicable. Example: 02.
"%p"Either AM or PM. Language dependent.
"%S"The two-digit second padded with a zero if applicable. Example: 04.
"%w"The numeric day of the week ranging from 0 to 6 where 0 is Sunday. Example: 0.
"%x"The language-aware standard date representation. For most languages, this is just the same as %B %d, %Y. Example: September 06, 2002.
"%X"The language-aware time representation. For most languages, this is just the same as %I:%M %p. Example: 04:31 PM.
"%y"The two-digit year padded with a leading zero if applicable. Example: 01.
"%Y"The four-digit year. Example: 2001.

Now you are a C programmer too!! :)
Title: Re: Clarification of os.date()
Post by: bastya_elvtars on 24 September, 2006, 23:49:25
Could you please run a wikify() on this? :)
Title: Re: Clarification of os.date()
Post by: Herodes on 25 September, 2006, 00:05:24
done ;) View it here (http://www.ptxwiki.psycho-chihuahua.net/doku.php/scriptinghelp/osdate)