01: /*
02: * BEGIN_HEADER - DO NOT EDIT
03: *
04: * The contents of this file are subject to the terms
05: * of the Common Development and Distribution License
06: * (the "License"). You may not use this file except
07: * in compliance with the License.
08: *
09: * You can obtain a copy of the license at
10: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
11: * See the License for the specific language governing
12: * permissions and limitations under the License.
13: *
14: * When distributing Covered Code, include this CDDL
15: * HEADER in each file and include the License file at
16: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
17: * If applicable add the following below this CDDL HEADER,
18: * with the fields enclosed by brackets "[]" replaced with
19: * your own identifying information: Portions Copyright
20: * [year] [name of copyright owner]
21: */
22:
23: /*
24: * @(#)I18NEchoTask.java
25: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
26: *
27: * END_HEADER - DO NOT EDIT
28: */
29: package com.sun.jbi.ui.ant.util;
30:
31: public class TimeUtil {
32: /* Constants */
33: private static final long DAY_BASE = 24 * 60 * 60 * 1000;
34: private static final long HOUR_BASE = 60 * 60 * 1000;
35: private static final long MIN_BASE = 60 * 1000;
36: private static final double SEC_BASE = 1000f;
37:
38: /* Private members */
39: private int mDays = 0;
40: private int mHours = 0;
41: private int mMins = 0;
42: private double mSecs = 0;
43:
44: /*
45: * public constructor
46: */
47: public TimeUtil(long theMs) {
48: mDays = (int) (theMs / DAY_BASE);
49: mHours = (int) ((theMs - mDays * DAY_BASE) / HOUR_BASE);
50: mMins = (int) ((theMs - mDays * DAY_BASE - mHours * HOUR_BASE) / MIN_BASE);
51: mSecs = ((theMs - mDays * DAY_BASE - mHours * HOUR_BASE - mMins
52: * MIN_BASE) / SEC_BASE);
53: }
54:
55: /**
56: * Get the days portion
57: * @return the days
58: */
59: public int getDays() {
60: return mDays;
61: }
62:
63: /**
64: * Get the hours portion
65: * @return the hours
66: */
67: public int getHours() {
68: return mHours;
69: }
70:
71: /**
72: * Get the minutes portion
73: * @return the minutes
74: */
75: public int getMins() {
76: return mMins;
77: }
78:
79: /**
80: * Get the seconds portion
81: * @return the seconds
82: */
83: public double getSecs() {
84: return mSecs;
85: }
86:
87: public static void main(String[] argv) {
88: long theLong = 2005;
89: TimeUtil inst = new TimeUtil(theLong);
90: System.out.format("Days: %1d Hours: %2d Mins: %3d Secs: %4f\n",
91: inst.getDays(), inst.getHours(), inst.getMins(), inst
92: .getSecs());
93: }
94: }
|