-
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathZipDate.cs
More file actions
37 lines (34 loc) · 1.38 KB
/
Copy pathZipDate.cs
File metadata and controls
37 lines (34 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
namespace System.IO.Compression
{
public static class ZipDate
{
/* DOS Date and time:
MS-DOS date. The date is a packed value with the following format. Bits Description
0-4 Day of the month (131)
5-8 Month (1 = January, 2 = February, and so on)
9-15 Year offset from 1980 (add 1980 to get actual year)
MS-DOS time. The time is a packed value with the following format. Bits Description
0-4 Second divided by 2
5-10 Minute (059)
11-15 Hour (023 on a 24-hour clock)
*/
public static uint DateTimeToDosTime(DateTime dt)
{
return (uint)(
(dt.Second / 2) | (dt.Minute << 5) | (dt.Hour << 11) |
(dt.Day << 16) | (dt.Month << 21) | ((dt.Year - 1980) << 25));
}
public static DateTime? DosTimeToDateTime(uint dt)
{
int year = (int)(dt >> 25) + 1980;
int month = (int)(dt >> 21) & 15;
int day = (int)(dt >> 16) & 31;
int hours = (int)(dt >> 11) & 31;
int minutes = (int)(dt >> 5) & 63;
int seconds = (int)(dt & 31) * 2;
if (month == 0 || day == 0 || year >= 2107)
return DateTime.Now;
return new DateTime(year, month, day, hours, minutes, seconds);
}
}
}