bsh for android : Time Test

beanshell : TimeTest.bsh

import java.io.*;
import java.net.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

DateFormat fmt = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
 
   /** UTC -> local Time
    */
   public static String getLocalTimeFromUTC(String UTCTime){
      java.util.Date UTCDate = null ;
      String localTimeStr = null ;
      try {
         UTCDate = fmt.parse(UTCTime);
         fmt.setTimeZone(TimeZone.getTimeZone("GMT+8")) ;
         localTimeStr = fmt.format(UTCDate) ;
      } catch (ParseException e) {
         e.printStackTrace();
      }
		 
      return localTimeStr ;
   }


      Calendar cal = new GregorianCalendar();
      zone = cal.getTimeZone().getID();
      print(zone);
      try
      {  
         Socket s = new Socket("time.nist.gov", 13);
         try
         {
            InputStream inStream = s.getInputStream();
            Scanner in = new Scanner(inStream);
            
            while (in.hasNextLine())
            {  
               String line = in.nextLine();
               // print(line);
               if (line.length() >24){                  
                  String UTC = line.substring(6,24);
                  print("UTC  "+UTC);
                  print("CN 20"+getLocalTimeFromUTC(UTC));
               }
            }
         }
         finally
         {
            s.close();
         }
      }
      catch (IOException e)
      {  
         e.printStackTrace();
      }

在 android 4.2 上测试成功


bsh for android : Time Test,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。