HOW TO :: get the system time and date
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

HOW TO :: get the system time and date

Started by Corayzon, 07 May, 2004, 08:02:16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Corayzon

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

[NL]Pur

date([%d %B %Y  l %X])

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

Corayzon

#3
thankz for the help once again

plop

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
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Optimus

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

Corayzon

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

plop

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 %
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Corayzon

cheerz plop dude!

thats more what i was after =]

Optimus

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

 ;)

Corayzon

hahaha...someone removes my harmless little joke

taripaz!  :rolleyes:

SMF spam blocked by CleanTalk