Total Pageviews

Monday, April 21, 2014

ចង់បង្កើត Date ទេ?

os.date()
នេះជាហ្វាំងសិនដែលប្រើសំរាប់បង្ហាញថ្ងៃ, វានឹងត្រលប់ជា String or a table ដែលផ្ទុកនៅ Date & Time, ចំណែកហ្វម៉ាត់របស់វាត្រូវបង្ហាញតាម String format
Syntax: os.date ( [ format [, time] ] )
Format(ជំរើស) វាជា String ដែលចាប់ផ្តើមជាមួយនឹង ពេលនោះថ្ងៃនឹងត្រូវ ហ្វម៉ាត់នៅក្នុង Coordinated Universal Time។ បន្ទាប់ពី Optional Character បើសិនជាហ្វម៉ាត់ជា String *t ពេលនោះថ្ងៃនឹងត្រឡប់ជា Table ជាមួយនឹងះ ឆ្នាំ(៤លេខ), ខែ(១ដល់១២), ថ្ងៃ(១ដល់៣១), ម៉ោង(០ដល់២៣), នាទី(០ដល់៥៩), វិនាទី(០ដល់៦១), ថ្ងៃក្នុងសប្តាហ៏(ចាប់ពីថ្ងៃអាទិត្យ), ថ្ងៃនៃឆ្នាំ, isdst (daylight saving flag, a boolean)
បើសិនជាហ្វម៉ាត់មិនមែនជា 
*t ពេលនោះវានឹងត្រឡប់ថ្ងៃជា String, ដែលដូចនឹង C Functions strftime(3)។ ដើម្បីងាយយល់កូដសូមមើលខាងក្រោមះ

%a       Abbreviated weekday name
%A      Full weekday name
%b       Abbreviated month name
%B      Full month name
%c       Date and time representation appropriate for locale
%d       Day of month as decimal number (01 – 31)
%H      Hour in 24-hour format (00 – 23)
%I        Hour in 12-hour format (01 – 12)
%j        Day of year as decimal number (001 – 366)
%m      Month as decimal number (01 – 12)
%M      Minute as decimal number (00 – 59)
%p       Current locale's A.M./P.M. indicator for 12-hour clock
%S      Second as decimal number (00 – 59)
%U      Week of year as decimal number, with Sunday as first day of week (00 – 53)
%w      Weekday as decimal number (0 – 6; Sunday is 0)
%W     Week of year as decimal number, with Monday as first day of week (00 – 53)
%x       Date representation for current locale
%X      Time representation for current locale
%y       Year without century, as decimal number (00 – 99)
%Y      Year with century, as decimal number
%z, %Z           The time-zone name or time zone abbreviation
%%      Percent sign

Time(ជំរើស) វាជាប្រភេទលេខបើសិនជា time argument is present, នេះជាពេលដែលត្រូវហ្វម៉ាត។ បើមិនដូចនោះទេ date formats the current time។ នៅពេលហៅវាដោយមិនមាន arguments, date នឹងត្រឡប់ជា a reasonable date & time ដែលតំណាងឪ្យការពឹងលើ host system នៅលើ current locale ដែលស្មើនឹង os.date(“%c”)
សូមមើលកូដះ
local date = os.date( "*t" )    -- returns table of date & time values
print( date.year, date.month )  -- print year and month
print( date.hour, date.min )    -- print hour and minutes
print( os.date( "%c" ) )        -- print out time/date string: e.g., "Thu Oct 23 14:55:02 2010"


No comments:

Post a Comment