Here's an example: 130814384725063210
If you type [Datetime]130814384725063210 into powershell it returns the date. Anyone know how to convert this information in AHK?
Appreciate any help
Mikael
Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
Re: Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
Code: Select all
[Datetime]130814384725063210 => Wednesday, 15. Juli 0415 12:54:32
[Datetime]10000000 => Monday, 1. Januar 0001 00:00:01
1 Second = 10000000
1 Second / 10000000 = 100 Nanoseconds
I think the problem here is the FILETIME structure
A. GetDateFormat works with minimum Date 160101010000000 (Monday, 01. Januar 1601)Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
Code: Select all
MsgBox % GetDateFormat(160101010000000) ; ==> Monday, 01. Januar 1601
GetDateFormat(Date, Format := "dddd',' dd. MMMM yyyy")
{
VarSetCapacity(SYSTEMTIME, 16)
, NumPut(SubStr(Date, 1, 4), SYSTEMTIME, 0, "UShort")
, NumPut(SubStr(Date, 5, 2), SYSTEMTIME, 2, "UShort")
, NumPut(SubStr(Date, 7, 2), SYSTEMTIME, 6, "UShort")
size := DllCall("GetDateFormat", "UInt", 0x0400, "UInt", 0, "Ptr", &SYSTEMTIME, "Ptr", &Format, "Ptr", 0, "Int", 0)
VarSetCapacity(buf, size * (A_IsUnicode ? 2 : 1), 0)
if !(DllCall("GetDateFormat", "UInt", 0x0400, "UInt", 0, "Ptr", &SYSTEMTIME, "Ptr", &Format, "Str", buf, "Int", size))
return "*" A_LastError
return buf
}
Code: Select all
FormatTime, TimeString, 1601010100000000, dddd, dd. MMMM yyyy hh:mm:ss
MsgBox % TimeString ; ==> Monday, 01. Januar 1601 12:00:00
Although only years between 1601 and 9999 are supported, a formatted time can still be produced for earlier years as long as the time portion is valid.
Maybe someone else has an idea to format this
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
I'm not even sure where that 0415 comes from, should be this year. Maybe [DateTime] doesn't work properly either.
IE: 130822047195938865, should be 24 June 2015 11:45
Currently I base it on File created time, but I figure if someone copy these files around, then that will break it.
IE: 130822047195938865, should be 24 June 2015 11:45
Currently I base it on File created time, but I figure if someone copy these files around, then that will break it.
Re: Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
In Powershell
Where you get the number from?
Code: Select all
[DATETIME]130822047195938865 ==> Friday, 24. July 0415 09:45:19
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
Name of the file. Ticks or something created by .NET
Re: Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
Name or Date of a file?
if you want the date of a file you can use skans function
if you want the date of a file you can use skans function
Code: Select all
MsgBox % FileGetTime("C:\Windows\System32\calc.exe")
FileGetTime(File, Mode := "M") ; by SKAN
{
if (VarSetCapacity($, 342, 0) && (H := DllCall("FindFirstFile", "Str", File, "Ptr", &$)))
{
DllCall("FindClose", "Ptr", H), VC := &$ + 4, VA := &$ + 12, VM := &$ + 20, FT := V%Mode%
LFT := &$ + 318 , DllCall("FileTimeToLocalFileTime", "Ptr", FT, "Ptr", LFT)
ST := LFT + 8 , DllCall("FileTimeToSystemTime", "Ptr", LFT, "Ptr", ST)
loop 7
T .= StrLen(N:= NumGet(ST + 0, (A_Index - 1) * 2, "UShort")) < 2 ? "0" N : N
return SubStr(T, 1, 6) SubStr(T, 9, 8) SubStr("00" NumGet(ST + 0, 14, "UShort"), -2)
}
}
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
File looks like this SHOW.TEST_130814384725063210.xml
Numbers are supposed to provide a date based on ticks from 1970 or something (.NET)
Numbers are supposed to provide a date based on ticks from 1970 or something (.NET)
- Blackholyman
- Posts: 1293
- Joined: 29 Sep 2013, 22:57
- Location: Denmark
- Contact:
Re: Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
Sounds like The Unix epoch
(or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking the epoch is Unix time 0 (midnight 1/1/1970), but 'epoch' is often used as a synonym for 'Unix time'. Many Unix systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038).
although this site does not give the date you ask for http://www.epochconverter.com/
(or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z). Literally speaking the epoch is Unix time 0 (midnight 1/1/1970), but 'epoch' is often used as a synonym for 'Unix time'. Many Unix systems store epoch dates as a signed 32-bit integer, which might cause problems on January 19, 2038 (known as the Year 2038 problem or Y2038).
although this site does not give the date you ask for http://www.epochconverter.com/
Courses on AutoHotkey
My Autohotkey Blog
Re: Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
Blackholyman, this site does the conversion somewhat correctly: http://tickstodatetime.com/
Tick (from filename): 130824030856564401
File created time (from windows): 26.07.2015 18:51
TicksToDatetime: 0415-07-26T16:51:25.657Z
Date is correct, but year should be 2015, not 0415
Tick (from filename): 130824030856564401
File created time (from windows): 26.07.2015 18:51
TicksToDatetime: 0415-07-26T16:51:25.657Z
Date is correct, but year should be 2015, not 0415
Re: Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
This seem to be FILETIME values: Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
As jNizM said: 1 second = 10000000 100-nanoseconds. So you have to divide the value by 10000000 to get the seconds, which can be easily added to a 1601 timestamp. The result will be UTC. If you want the local time, you have to process an appropriate conversion.
Just a guess:
As jNizM said: 1 second = 10000000 100-nanoseconds. So you have to divide the value by 10000000 to get the seconds, which can be easily added to a 1601 timestamp. The result will be UTC. If you want the local time, you have to process an appropriate conversion.
Code: Select all
FileTicks := 130824030856564401
FileSeconds := FileTicks // 10000000
DateTimeUTC := 1601
DateTimeUTC += FileSeconds, S
LocalTicks := FileTimeToLocalFileTime(FileTicks)
FileSeconds := LocalTicks // 10000000
DateTimeLoc := 1601
DateTimeLoc += FileSeconds, S
MsgBox, UTC:`n%DateTimeUTC%`nLocal:`n%DateTimeLoc%
FileTimeToLocalFileTime(FileTicks) { ; 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC)
VarSetCapacity(FileTime, 8, 0)
VarSetCapacity(LocalTime, 8, 0)
NumPut(FileTicks, FileTime, "UInt64")
DllCall("FileTimeToLocalFileTime", "Ptr", &FileTime, "Ptr", &LocalTime)
Return NumGet(LocalTime, "UInt64")
}
What do you get if you add 04 to 16?Date is correct, but year should be 2015, not 0415
Re: Convert .NET DateTime ticks to AHK YYYYMMDDHH24MISS timestamp
@just me: This works great. Sorry for late reply. Thanks so much
Who is online
Users browsing this forum: No registered users and 254 guests