⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utility.java

📁 彩信网关程序。只支持发送。
💻 JAVA
字号:
package mmscenter;import java.io.*;import java.util.*;import sun.io.*;/** * <p>Title: Simens SMS Tool</p> * <p>Description: 西门子铃声图片工具 1.0</p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: 北京映翰通网络技术有限公司</p> * @author rjz rjz@inhand.com.cn * @version 1.0 */public class Utility{  public Utility() {  }  public static String getDateString(Calendar calendar){    String result="";    result+=calendar.get(Calendar.YEAR);    int month=calendar.get(Calendar.MONTH)+1;    if(month<10)      result+="-0"+month;    else      result+="-"+month;    if(calendar.get(Calendar.DATE)<10)      result+="-0"+calendar.get(Calendar.DATE);    else      result+="-"+calendar.get(Calendar.DATE);    return result;  }  public static String getDateString(){    String result="";    Calendar calendar=Calendar.getInstance();    result+=calendar.get(Calendar.YEAR);    int month=calendar.get(Calendar.MONTH)+1;    if(month<10)      result+="-0"+month;    else      result+="-"+month;    if(calendar.get(Calendar.DATE)<10)      result+="-0"+calendar.get(Calendar.DATE);    else      result+="-"+calendar.get(Calendar.DATE);    return result;  }  public static String getTimeString(){    String result="";    Calendar calendar=Calendar.getInstance();    if(calendar.get(Calendar.HOUR_OF_DAY)<10)      result+="0"+calendar.get(Calendar.HOUR_OF_DAY);    else      result+=calendar.get(Calendar.HOUR_OF_DAY);    if(calendar.get(Calendar.MINUTE)<10)      result+=":0"+calendar.get(Calendar.MINUTE);    else      result+=":"+calendar.get(Calendar.MINUTE);    if(calendar.get(Calendar.SECOND)<10)      result+=":0"+calendar.get(Calendar.SECOND);    else      result+=":"+calendar.get(Calendar.SECOND);    return result;  }  public static long createTime(){         long result;         Calendar calendar=Calendar.getInstance();         result = calendar.getTime().getTime() ;         return result;  }  public static int getInt(String hexStr){   int[] digit=new int[4];   int result=0;   for (int i=0;i<4;i++){       digit[i]=Integer.parseInt(hexStr.substring(i*2,i*2+2),16);   }   result = digit[0]+digit[1]*256+digit[2]*256*256+digit[3]*256*256*256;   return result;  }  public static short getShort(String hexStr){   int[] digit=new int[2];   short result;   for (int i=0;i<2;i++){       digit[i]=Integer.parseInt(hexStr.substring(i*2,i*2+2),16);   }   result = (short)(digit[0]+digit[1]*256);   return result;  }  public static String toHexString(String str){    byte temp[]=new byte[str.length()];    temp=str.getBytes();    String result="";    for (int i=0;i<str.length();i++){      result+=toHexString(temp[i]);    }    return result;  }  public static String usctoHexString(String str){  byte temp[]=new byte[str.length()];  temp=str.getBytes();  String result="";  for (int i=0;i<str.length();i++){    result+="00";    result+=toHexString(temp[i]);  }    return result;  }  public static String toHexString(byte[] b){    String result="";    try {  for (int i=0;i<b.length;i++){      result+=toHexString(b[i]);  }    }catch(Exception e){         e.printStackTrace();   }    return result;  }  public static String toHexString(byte[] b,int offset,int len){    String result="";    try {  for (int i=offset;i<len+offset;i++){      result+=toHexString(b[i]);  }    }catch(Exception e){         e.printStackTrace();   }    return result;  }  public static String toHexString(int op){    int temp[]=new int[4];    String s="";    for (int i=0;i<4;i++){      temp[i]=(op&(0x000000ff<<i*8))>>(i*8);      s+=toHexString((byte)temp[i]);    }    return s;  }  public static String toHexString(short op){    int temp[]=new int[2];    String s="";    for (int i=0;i<2;i++){      temp[i]=(op&(0x000000ff<<i*8))>>(i*8);      s+=toHexString((byte)temp[i]);    }    return s;  }  public static String toHexString(byte b){    int tmp=(b&0x000000f0)>>4;    String result=Integer.toHexString(tmp);    tmp=b&0x0000000f;    result+=Integer.toHexString(tmp);    return result;  }  public static String getRMBYuanString(String fenNumber){  String yuan="";  if (fenNumber.startsWith("-")){    yuan="-";    fenNumber=fenNumber.substring(1);  }  if (fenNumber.length()<=2){    if (fenNumber.length()<=1)      return yuan+"0.0"+fenNumber;    else      return yuan+"0."+fenNumber;  }else{    yuan+=fenNumber.substring(0,fenNumber.length()-2);    String fen=fenNumber.substring(fenNumber.length()-2,fenNumber.length());    return yuan+"."+fen;  }  }  public static String getCutString(String longStr){  if (longStr.length()<=60){    return new String(longStr);  }else{    return new String(longStr.substring(0,60)+" ...");  }  }  public static String getTimeStr(){    String result="";    Calendar calendar=Calendar.getInstance();    if(calendar.get(Calendar.HOUR_OF_DAY)<10)      result+="0"+calendar.get(Calendar.HOUR_OF_DAY);    else      result+=calendar.get(Calendar.HOUR_OF_DAY);    if(calendar.get(Calendar.MINUTE)<10)      result+="0"+calendar.get(Calendar.MINUTE);    else      result+=""+calendar.get(Calendar.MINUTE);    if(calendar.get(Calendar.SECOND)<10)      result+="0"+calendar.get(Calendar.SECOND);    else      result+=""+calendar.get(Calendar.SECOND);    return result;  }  public static String AsciiToChineseString(String s) {        char[] orig = s.toCharArray();        byte[] dest = new byte[orig.length];        for (int i=0;i<orig.length;i++)          dest[i] = (byte)(orig[i]&0xFF);        try {          ByteToCharConverter toChar = ByteToCharConverter.getConverter("gb2312");          return new String(toChar.convertAll(dest));        }        catch (Exception e) {          System.out.println(e);          return s;        }  }    public static String ChineseStringToAscii(String s) {        try {          CharToByteConverter toByte = CharToByteConverter.getConverter("gb2312");          byte[] orig = toByte.convertAll(s.toCharArray());          char[] dest = new char[orig.length];          for (int i=0;i<orig.length;i++)      dest[i] = (char)(orig[i] & 0xFF);          return new String(dest);        }        catch (Exception e) {          System.out.println(e);          return s;        }    }/*  public static void main(String[] args) {  try{    Calendar now=Calendar.getInstance();    System.out.println(Utility.getDateString()+" "+Utility.getTimeString());    Thread.sleep(5000);    System.out.println(Utility.getDateString()+" "+Utility.getTimeString());    Thread.sleep(5000);    System.out.println(Utility.getDateString()+" "+Utility.getTimeString());  }catch(Exception e){    e.printStackTrace();  }  System.out.println(Utility.getRMBYuanString("230"));  }*/}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -