home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Japan / NTT / DM- / hotjava / classes / src / GMTTime.java < prev    next >
Encoding:
Java Source  |  2017-09-21  |  1.1 KB  |  44 lines

  1. import java.util.*;
  2.  
  3. // GMTTime    $B8=:_$N(BGMT$B;~9o$^$?$O%m!<%+%k;~9o$rJV$94X?t(B
  4. //        $B;~9o$O!"D9$5(B3$B$N(Bint$B$NG[Ns$G!"@hF,$NMWAG$+$i=g$K;~(B,$BJ,(B,$BIC$,(B
  5. //        $BF~$C$F$$$k(B
  6. // Functions:
  7. //    GMTTime()    constructor
  8. //    getTime(int h)    h $B;~4V?J$s$@(B(h < 0 $B$J$iCY$l$?(B)$BCO0h$N;~9o$rJV$9(B
  9. //    getHour(int h)    h $B;~4V?J$s$@(B(h < 0 $B$J$iCY$l$?(B)$BCO0h$N(B"$B;~(B"$B$rJV$9(B
  10. //
  11.  
  12. class GMTTime extends Object {
  13.     int gmttime[];
  14.  
  15. public GMTTime() {
  16.     gmttime = new int[3];
  17.     String GMTdate = new Date().toGMTString();
  18.     int pos = GMTdate.indexOf(":");        // search time separator
  19.     gmttime[0] = Integer.parseInt(GMTdate.substring(pos-2,pos));     // hour
  20.     gmttime[1] = Integer.parseInt(GMTdate.substring(pos+1,pos+3));    // min
  21.     gmttime[2] = Integer.parseInt(GMTdate.substring(pos+4,pos+6));    // sec
  22. }
  23.  
  24. public int[] getTime(int h) {
  25.     int localtime[] = new int[3];
  26.     localtime[0] = gmttime[0] + h;
  27.     if (localtime[0] > 24) {
  28.         localtime[0] -= 24;
  29.     }
  30.     localtime[1] = gmttime[1];
  31.     localtime[2] = gmttime[2];
  32.     return localtime;
  33. }
  34.  
  35. public int getHour(int h) {
  36.     int hour = gmttime[0] + h;
  37.     if (hour > 24) {
  38.         hour -= 24;
  39.     }
  40.     return hour;
  41. }
  42. }
  43.  
  44.