Skip to content

How to return current date string? #1

@c4thead

Description

@c4thead

Hello, i've been trying to return a current date string in format YYYY.MM.DD but the LuaPlayer 0.20 will return 1970.01.01
I know that nobody really codes for PSP on an oldass LuaPlayer but that's my hobby and really the only thing i've gotten myself into, i used to program on it since 2016

The functions i assembled are:

function getTimeStr_HH_MM_SS()
	time = os.time()
	dateString = os.date("%c", time)
	dateFields = os.date("*t", time)

	hour = dateFields.hour
	if hour < 10 then hour = "0" .. hour end
	min = dateFields.min
	if min < 10 then min = "0" .. min end
	sec = dateFields.sec
	if sec < 10 then sec = "0" .. sec end

	return tostring(hour..""..min..""..sec)
end

function getDateStr_YYYY_MM_DD()
	time = os.time()
    Year = os.date("%Y", time)
    Month = os.date("%m", time)
    Day = os.date("%d", time)
	return string.format("%04d%02d%02d", Year, Month, Day)
end

And whenever i try to save the image by combining these two:

Canvas:save("Workspace/"..getDateStr_YYYY_MM_DD().."_"..getTimeStr_HH_MM_SS()..".png")

It ended up for me as 19700101_120539.png with the correct hour, minute, second but wrong year, month, day.
The time is right but the date is the default, is there anything that i do wrong or the LuaPlayer doesn't know how to fetch the right date?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions