 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Mon Jul 22, 2019 1:02 am Post subject: Formating seconds to string format. |
|
|
I try to output the time span in seconds to following:
| Code: | function SecondsFormat(X)
if X <= 0 then return "" end
local date = os.date("%c", X)
local inPattern = "(%d+)/(%d+)/(%d+) (%d+):(%d+):(%d+)"
local outPattern = "%dy:%dm:%dd:%dh:%dm:%ds"
local month, day, year, hour, minute, second = date:match(inPattern)
month = month - 1
day = day - 1
year = year - 70
return string.format(outPattern, year, month, day, hour, minute, second)
end
|
The function above will output, string format example: 1y:2m:21d:17h:25m:11s
But, I want output as: 01:02:21:17:25:11
How to write the output pattern?
And let say I have variables:
| Code: | | local year, month, day, hour, minute, second = 2019, 12, 31, 23, 59, 01 |
Then I need to concatenate those variables so I can use os.time(os.date(*t)) from a specific date+time as store on those variables. How?
Thanks.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25838 Location: The netherlands
|
Posted: Mon Jul 22, 2019 2:13 am Post subject: |
|
|
use %.2d for the 2 digit format, no idea about the rest
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1535
|
Posted: Mon Jul 22, 2019 4:55 am Post subject: |
|
|
it seems to give you the result you want.
| Code: | function SecondsFormat()
local year = tostring(os.date('%Y')) -- or %y = 19:07:22-13:49:07
local month = tostring(os.date('%m'))
local day = tostring(os.date('%d'))
local hour = tostring(os.date('%p' < '%I' or '%H'))
local minute = tostring(os.date('%M'))
local second = tostring(os.date('%S'))
print(tostring(os.date(year..':'..month..':'..day..'-'..hour..':'..minute..':'..second)))
end
SecondsFormat()
--result = 2019:07:22-13:50:30 |
| Code: | function SecondsFormat1()
local year = tostring(os.date('%Y')) -- or %y = 19
local month = tostring(os.date('%B'))
local day = tostring(os.date('%A'))
local hour = tostring(os.date('%p' < '%I' or '%H'))
local minute = tostring(os.date('%M'))
local second = tostring(os.date('%S'))
print(tostring(os.date(year..' / '..month..' / '..day..' /-/ '..hour..':'..minute..':'..second)))
end
SecondsFormat1()
--result: 2019 / July / Monday /-/ 14:03:21 |
_________________
|
|
| Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Mon Jul 22, 2019 5:40 am Post subject: |
|
|
| Dark Byte wrote: | | use %.2d for the 2 digit format, no idea about the rest |
Yes, thank DB. "%2d" give 2 digit format value, but not leading zero value if the value as 1 digit. So, I use "%02.f" to output all value with 2 digits.
@Aylin : That not I want. What I want is to return seconds or seconds left to date and time format. I solved it :
| Code: | local yr, mn, dy, hr, mt, sc = 2019, 12, 31, 23, 59, 01
local date_tbl = { year = yr, month = mn, day = dy, hour = hr, minute = mt, second = sc }
local targetTime = os.time( date_tbl )
print(os.date("%a, %d %b %Y %H:%M:%S", targetTime ))
-- result : Tue, 31 Dec 2019 23:00:00
print(os.date( "!%A, %d-%B-%Y %H:%M:%S" , targetTime + 1 * 60 * 60 ))
-- result : Tuesday, 31-December-2019 17:00:00
|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25838 Location: The netherlands
|
Posted: Mon Jul 22, 2019 9:14 am Post subject: |
|
|
| Corroder wrote: | | Dark Byte wrote: | | use %.2d for the 2 digit format, no idea about the rest |
Yes, thank DB. "%2d" give 2 digit format value, but not leading zero value if the value as 1 digit. So, I use "%02.f" to output all value with 2 digits.
|
I said, %.2d, not %2d
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Mon Jul 22, 2019 9:17 am Post subject: |
|
|
| Dark Byte wrote: |
I said, %.2d, not %2d |
Ah, sorry, I don't see that dot before 2d. Yes, it works properly. Thanks, DB.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|