Difference between revisions of "Talk:love.timer"

(Created page with "Is here some way to get time from 1970 in seconds with milliseconds? Like this: <source lang="lua"> local starting_time = os.time() -- time in seconds function love.timer.get...")
 
m
Line 12: Line 12:
 
end
 
end
 
</source>
 
</source>
 +
 +
[http://w3.impa.br/~diego/software/luasocket/socket.html#gettime socket.gettime()] return time in seconds relative to origin of the universe (1 Jan 1970) with microseconds precision
 +
<source lang="lua">
 +
socket = require 'socket'
 +
 +
function love.draw()
 +
love.graphics.print(('%.4f seconds passed since origin of the universe (1 Jan 1970)'):format(socket.gettime()), 32, 32)
 +
-- Prints something like: 1614267059.6269 seconds passed since origin of the universe (1 Jan 1970)
 +
-- string.format is used to fix number of digits after decimal point
 +
end
 +
</source>
 +
--[[User:Andlac028|Andlac028]] ([[User talk:Andlac028|talk]]) 16:41, 25 February 2021 (CET)

Revision as of 15:41, 25 February 2021

Is here some way to get time from 1970 in seconds with milliseconds? Like this:

local starting_time = os.time() -- time in seconds

function love.timer.getTime()
	return starting_time + os.clock () -- time in seconds and time from game start
end

function love.draw()
	love.graphics.print(love.timer.getTime(), 32,32)
end

socket.gettime() return time in seconds relative to origin of the universe (1 Jan 1970) with microseconds precision

socket = require 'socket'

function love.draw()
	love.graphics.print(('%.4f seconds passed since origin of the universe (1 Jan 1970)'):format(socket.gettime()), 32, 32)
	-- Prints something like: 1614267059.6269 seconds passed since origin of the universe (1 Jan 1970)
	-- string.format is used to fix number of digits after decimal point
end

--Andlac028 (talk) 16:41, 25 February 2021 (CET)