PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Corayzon on 07 May, 2004, 08:02:16

Title: HOW TO :: get the system time and date
Post by: Corayzon on 07 May, 2004, 08:02:16
leyoyo pplz

just wanted a funtion for the following ::

function getTime() -- hh:mm:ss am\pm
function getData() -- dd/mm/yyyy

i know you use the format string but how does it work exactly?

thankz guyz
Title:
Post by: [NL]Pur on 07 May, 2004, 13:43:49
date([%d %B %Y  l %X])
Title:
Post by: Optimus on 07 May, 2004, 13:47:05
Here another example about the time (am/pm)
function LocalTimeDisplay()
local sHour = date("%H")
local sMin = date("%M")
local sSec = date("%S")
local sExtend = ""
if tonumber(sHour) >= 00 and tonumber(sHour) < 12 then
sExtend = "am"
else
sExtend = "pm"
end
sTime = ("Hub local time - "..sHour..":"..sMin..":"..sSec..""..sExtend)
SendToAll(sBot, sTime)
end
Title:
Post by: Corayzon on 07 May, 2004, 13:57:09
thankz for the help once again
Title:
Post by: plop on 07 May, 2004, 16:54:22
QuoteOriginally posted by Optimus
Here another example about the time (am/pm)
function LocalTimeDisplay()
local sHour = date("%H")
local sMin = date("%M")
local sSec = date("%S")
local sExtend = ""
if tonumber(sHour) >= 00 and tonumber(sHour) < 12 then
sExtend = "am"
else
sExtend = "pm"
end
sTime = ("Hub local time - "..sHour..":"..sMin..":"..sSec..""..sExtend)
SendToAll(sBot, sTime)
end

you got a posible bug here.
think what can happen on 11:59:59.
it can return 11:00:00.
always grab the full time and split it with strfind.

plop
Title:
Post by: Optimus on 07 May, 2004, 18:12:19
thx plop here ya go :D

function LocalTimeDisplay()
local s,e,sHour,sMin,sSec = strfind(date("%T"),"(%d+)%:(%d+)%:(%d+)")
if tonumber(sHour) >= 00 and tonumber(sHour) < 12 then
sExtend = "am"
else
sExtend = "pm"
end
SendToAll(sBot, "Hub local time - "..sHour..":"..sMin..":"..sSec..""..sExtend)
end
Title:
Post by: Corayzon on 08 May, 2004, 04:30:19
thankz guyz =]

my end result

function getTime()
local _,_, dHour, dMin, dSec, dExtend = strfind(date("%T"),"(%d+)%:(%d+)%:(%d+)")
if tonumber(dHour) >= 00 and tonumber(dHour) < 12 then
dExtend = "am"
else
dExtend = "pm"
end
return dHour .. ":" .. dMin .. ":" .. dSec .. " " .. dExtend
end

function getDate()

return date("%d %m %y")

end
Title:
Post by: plop on 08 May, 2004, 17:25:15
take a look @ this corayzon, that am/pm can be done in a easyer way.
%Y full year (1998)
%y year, with two digits (98) [00?99]
%m month (09) [01?12]
%B full month name (September)
%b abbreviated month name (Sep)
%d day of the month (16) [01?31]
%w weekday (3) [0?6 = Sunday?Saturday]
%A full weekday name (Wednesday)
%a abbreviated weekday name (Wed)
%H hour, using a 24-hour clock (23) [00?23]
%I hour, using a 12-hour clock (11) [01?12]
%p either "am" or "pm" (pm)
%M minute (48) [00?59]
%S second (10) [00?61]
%c date and time (09/16/98 23:48:10)
%x date (09/16/98)
%X time (23:48:10)
%% the character %
Title:
Post by: Corayzon on 08 May, 2004, 23:16:37
cheerz plop dude!

thats more what i was after =]
Title:
Post by: Optimus on 09 May, 2004, 00:27:08
Ha thx

i don't see a reason any more to split that time up in strings. This is way faster YUPS. The stringfind was there to get the Hours and calculate the am/pm thingy. but euhh lets dump that code

date("%T %p") - will do fine now no need for the other code anymore

 ;)
Title:
Post by: Corayzon on 09 May, 2004, 15:16:19
hahaha...someone removes my harmless little joke

taripaz!  :rolleyes: