KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > NTTime


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb;
18
19 import java.util.Date JavaDoc;
20
21 /**
22  * NT 64bit Time Conversion Class
23  * <p>
24  * Convert an NT 64bit time value to a Java Date value and vice versa.
25  */

26 public class NTTime
27 {
28     // NT time value indicating infinite time
29

30     public static final long InfiniteTime = 0x7FFFFFFFFFFFFFFFL;
31
32     // Time conversion constant, difference between NT 64bit base date of 1-1-1601 00:00:00 and
33
// Java base date of 1-1-1970 00:00:00. In 100ns units.
34

35     private static final long TIME_CONVERSION = 116444736000000000L;
36
37     /**
38      * Convert a Java Date value to an NT 64bit time
39      *
40      * @param jdate Date
41      * @return long
42      */

43     public final static long toNTTime(Date JavaDoc jdate)
44     {
45
46         // Add the conversion constant to the Java date raw value, convert the Java milliseconds to
47
// 100ns units
48

49         long ntDate = (jdate.getTime() * 10000L) + TIME_CONVERSION;
50         return ntDate;
51     }
52
53     /**
54      * Convert a Java Date value to an NT 64bit time
55      *
56      * @param jdate long
57      * @return long
58      */

59     public final static long toNTTime(long jdate)
60     {
61
62         // Add the conversion constant to the Java date raw value, convert the Java milliseconds to
63
// 100ns units
64

65         long ntDate = (jdate * 10000L) + TIME_CONVERSION;
66         return ntDate;
67     }
68
69     /**
70      * Convert an NT 64bit time value to a Java date value
71      *
72      * @param ntDate long
73      * @return SMBDate
74      */

75     public final static SMBDate toSMBDate(long ntDate)
76     {
77
78         // Convert the NT 64bit 100ns time value to a Java milliseconds value
79

80         long jDate = (ntDate - TIME_CONVERSION) / 10000L;
81         return new SMBDate(jDate);
82     }
83
84     /**
85      * Convert an NT 64bit time value to a Java date value
86      *
87      * @param ntDate long
88      * @return long
89      */

90     public final static long toJavaDate(long ntDate)
91     {
92
93         // Convert the NT 64bit 100ns time value to a Java milliseconds value
94

95         long jDate = (ntDate - TIME_CONVERSION) / 10000L;
96         return jDate;
97     }
98 }
99
Popular Tags