路是爬出來的
導航
BlogJava
首頁
新隨筆
聯系
聚合
管理
<
2025年7月
>
日
一
二
三
四
五
六
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
統計
隨筆 - 50
文章 - 50
評論 - 2
引用 - 0
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(1)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2006年12月 (50)
文章檔案
2006年12月 (50)
搜索
最新評論
1.?re: RMS詳細例子[未登錄]
FUCK
--AA
2.?re: 以前設計的一款小游戲共享出來
sdf
--sdf
閱讀排行榜
1.?游戲入門之一 雷電 精靈模型(1316)
2.?關于Map.entrySet()的疑惑(1060)
3.?XmlPullParser 的例子(557)
4.? 設計可組裝的j2me UI(四) 時間控件(456)
5.?WML 標簽跟WML學習(430)
評論排行榜
1.?RMS詳細例子(1)
2.?以前設計的一款小游戲共享出來(1)
3.?j2me常用的字符,日期,以及轉換編碼實現(0)
4.?高燃被T(0)
5.?DOS命令大全(經典收藏)(0)
[導入]j2me常用的字符,日期,以及轉換編碼實現
代碼
import java.io.UnsupportedEncodingException; import java.util.Vector; import javax.wireless.messaging.Message; /** * 轉換網絡傳過來的數據 * * @auth colonel * @dateOrLeague 2006-7-11 * */ public class StringUtil { /** * 切割str字符串 * 例如("wuhua,中國,好,",",");分割成String[] s = {"wuhua","中國","好"); * @param str 源字符串 * @param regex,分割標致, * @return */ public static String[] split(String bufferstr, String regex) { if(bufferstr == null) return null; Vector split = new Vector(); while (true) // 處理從網絡上獲得的數據并對其進行處理 { int index = bufferstr.indexOf(regex); if (index == -1) { if (bufferstr != null && !bufferstr.equals("")) split.addElement(bufferstr); // log.debug("bufferstr=" +bufferstr);s break; } split.addElement(bufferstr.substring(0, index)); // log.debug("Str=" + bufferstr.substring(0, index)); bufferstr = bufferstr.substring(index + 1, bufferstr.length()); // log.debug("bufferstr=" +bufferstr); } String[] s = new String[split.size()]; split.copyInto(s); return s; } /** * 轉換網絡上的字節為中文 * @param bytes * @param start * @return */ public static String getStringToGBK(byte[] bytes, int start) { byte[] rt = new byte[bytes.length - start]; for (int i = 0; i < rt.length; i++) rt[i] = bytes[i + start]; try { return new String(rt, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return new String(rt); } } }
代碼
/** * 轉換編碼 * @author Administrator * */ public class FormatTransfer { public static int getUINT4(byte ba[], int start) { int r = 0; r |= 0xff & ba[start]; r <<= 8; r |= 0xff & ba[start + 1]; r <<= 8; r |= 0xff & ba[start + 2]; r <<= 8; r |= 0xff & ba[start + 3]; return r; } public static void setUINT4(byte ba[], int start, int value) { ba[start] = (byte) (value >> 24 & 0xff); ba[start + 1] = (byte) (value >> 16 & 0xff); ba[start + 2] = (byte) (value >> 8 & 0xff); ba[start + 3] = (byte) (value & 0xff); } public static void setUSHORT4(byte ba[], int start, short value) { ba[start + 0] = (byte) (value >> 8 & 0xff); ba[start + 1] = (byte) (value & 0xff); } public static short getUSHORT4(byte ba[], int start) { short r = 0; r |= 0xff & ba[start]; r <<= 8; r |= 0xff & ba[start + 1]; return r; } public static void appen(byte[] rt, byte[] bodys, int start) { for (int i = 0; i < bodys.length; i++) { rt[start + i] = bodys[i]; } } }
代碼
import java.util.Calendar; import java.util.Date; import java.util.TimeZone; /** *
類名:DateTime.java
編寫日期: 2006-6-23 程序功能描述:日期時間的工具類 * Demo: Bug: * * 程序變更日期 : 變更作者 : 變更說明 : * * @author wuhua
rrq12345@163.com
*/ public final class DateTime { private static String[] WEEKDAYS_EN = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; private static String[] WEEKDAYS_CH = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" }; public final String timeZone; public final int year; public final int month; public int day; public int weekday; public final int hour; public final int minute; public final int second; public final int millsecond; Calendar c; public DateTime(Date date, String timeZone) { this.timeZone = timeZone; c = timeZone == null ? Calendar.getInstance() : Calendar .getInstance(TimeZone.getDefault()); c.setTime(date); year = c.get(Calendar.YEAR); month = c.get(Calendar.MONTH); day = c.get(Calendar.DAY_OF_MONTH); weekday = c.get(Calendar.DAY_OF_WEEK); hour = c.get(Calendar.HOUR_OF_DAY); minute = c.get(Calendar.MINUTE); second = c.get(Calendar.SECOND); millsecond = c.get(Calendar.MILLISECOND); } public DateTime(long time, String timeZone) { this(new Date(time), timeZone); } public DateTime() { this(System.currentTimeMillis(), "GMT + 16"); } public static String beforeOneDate() { return new DateTime(System.currentTimeMillis() - 24 * 3600 * 1000, "GMT+8").toDateString(); } public Date toDate() { Calendar c = Calendar.getInstance(TimeZone.getTimeZone(timeZone)); c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, month); c.set(Calendar.DAY_OF_MONTH, day); c.set(Calendar.HOUR_OF_DAY, hour); c.set(Calendar.MINUTE, minute); c.set(Calendar.SECOND, second); c.set(Calendar.MILLISECOND, millsecond); return c.getTime(); } public String toDateString() { if (timeZone.equals("GMT-8")) return (month + 1) + "月" + day + "日" + " [" + WEEKDAYS_EN[weekday - 1] + "] "; else return (month + 1) + "月" + day + "日" + " [" + WEEKDAYS_CH[weekday - 1] + "] "; } public void setDate(int day) { this.day = day; this.c.set(Calendar.DAY_OF_WEEK, day); // day = c.get(Calendar.DAY_OF_WEEK); weekday = c.get(Calendar.DAY_OF_WEEK); } public String toTimeString() { return hour + ":" + minute + ":" + second + ":" + millsecond; } public String toString() { return toDateString() + " " + toTimeString(); } }
文章來源:
http://wuhua.javaeye.com/blog/33407
posted on 2006-12-30 08:44
路是爬出來的
閱讀(102)
評論(0)
編輯
收藏
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
Powered by:
BlogJava
Copyright © 路是爬出來的
主站蜘蛛池模板:
大安市
|
云浮市
|
库伦旗
|
福泉市
|
永修县
|
新巴尔虎左旗
|
龙陵县
|
江山市
|
河源市
|
七台河市
|
延安市
|
沁阳市
|
井研县
|
德昌县
|
会泽县
|
吐鲁番市
|
滨州市
|
长葛市
|
永平县
|
什邡市
|
长白
|
闵行区
|
石棉县
|
清新县
|
连城县
|
河源市
|
宝兴县
|
霍邱县
|
龙南县
|
门头沟区
|
白河县
|
垫江县
|
昌都县
|
武宁县
|
多伦县
|
临清市
|
涞源县
|
那坡县
|
黔南
|
启东市
|
靖安县
|