CODE34編碼
規則
1. CODE34編碼如下: (數字0到9) + (英文字母扣掉容易混淆的IO) = 10 + 24 = 34 0 1 2 3 0123456789012345678901234567890123 0123456789ABCDEFGHJKLMNPQRSTUVWXYZ 2. 不分大小寫. 程式中先轉為大寫字母以後才開始使用, 並以大寫字母存檔. 3. 英文字母I跟O, 因容易與數字1跟0混淆, 因此不併入編碼.
CODE34ID
格式: YYMDHSSSNN YY: 西元1900到3055年 = 00到ZZ 1900 1901 1902 .... 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 00 01 02 37 38 39 3A 3B 3C 3D 3E 3F 3G 3H 3J M: (1-12) = (1-C) D: (1-31) = (1-X) H: (0-23) = (0-P) SSS: 一小時總秒數 = (0-3600) = (000-33W) NN: (0-999) = (00-VD)。(milli-second或與時間無關的序號循環使用) 特性: 1. 以10位英數字, 取代17位數字(yyyyMMddHHmmssNNN). 2. 仍保持原有數字的有向序號特性, 可排序, 並可簡化使用者輸入, 不易錯誤. 注意: 1.若可取得千分之一秒, 則直接以milli-second填入NN. 2.若無法取得千分之一秒時, 則自行填入(0-999). 若最大號需要進位時, 則須延遲一秒鐘, 使秒數進位後, 再取值才能保持依序編號. 限制: 每秒1000筆編碼不重複.
快速對照表
0 1 2 3 0123456789012345678901234567890123 0123456789ABCDEFGHJKLMNPQRSTUVWXYZ 10進位 Code34進位 33 Z 1,155 ZZ 39,303 ZZZ 1,336,335 ZZZZ 45,435,423 ZZZZZ 1,544,804,415 ZZZZZZ 52,523,804,415 ZZZZZZZ 1,785,793,904,895 ZZZZZZZZ 9 9 99 2X 999 VD 9,999 8N3 99,999 2JH5 999,999 RF1R 9,999,999 7GEHM 99,999,999 26U96F 999,999,999 N0APWP 3,600 33W (一小時總秒數) 86,400 26R6 (一天總秒數)
適用狀況
簡化編碼, 可用較短的格式代表較長編碼的代號, 減少混淆的文數字輸入錯誤. 例如: 格式為YYYYMMDDHHNNSSQQQ, 原需要以17個數字表示, 改用CODE34編碼則可簡化為10個文數字即可.
參考
常用日期時間public DateTime(int year(1-9999), int month(1-12), int day(1-31), int hour(0-23), int minute(0-59), int second(0-59), int millisecond(0-999)) DateTime date1 = new DateTime(2010, 8, 18, 16, 32, 18, 500); Console.WriteLine(date1.ToString("M/dd/yyyy h:mm:ss.fff tt")); // 8/18/2010 4:32:18.500 PM Console.WriteLine(date1.ToString("yyyy-MM-dd HH:mm:ss.fff")); // 2010-08-18 16:32:18.500 XML: <FTimeStart>2014-09-01T16:59:52.3805556+08:00</FTimeStart> DateTime d1 = new DateTime(2014, 9, 8, 11, 03, 25, 500); byte[] baTime1 = ZByte.GetBytes(d1); int iYear = BitConverter.ToUInt16(baTime1, 0); int iMonth = baTime1[2]; int iDay = baTime1[3]; int iHour = baTime1[4]; int iMinute = baTime1[5]; int iSecond = baTime1[6]; int iMilliSecond = BitConverter.ToUInt16(baTime1, 7); DateTime d2 = new DateTime(iYear, iMonth, iDay, iHour, iMinute, iSecond, iMilliSecond); string s1 = BitConverter.ToString(baTime1); byte[] baTime2 = ZByte.GetBytes(d2); string s2 = BitConverter.ToString(baTime1); string s3 = "DE-07-09-08-0B-03-19-F4-01"; CProject.TraceMsg("s1={0}.", s1); // ="DE-07-09-08-0B-03-19-F4-01" CProject.TraceMsg("s2={0}.", s2); // ="DE-07-09-08-0B-03-19-F4-01" CProject.TraceMsg("s3={0}.", s3); // ="DE-07-09-08-0B-03-19-F4-01" public static byte[] GetBytes(DateTime dValue) { byte[] baTime = new byte[9]; Copy(GetBytes(dValue.Year), 0, baTime, 0, 2); // year 0 to 65535 Copy(GetBytes(dValue.Month), 0, baTime, 2, 1); Copy(GetBytes(dValue.Day), 0, baTime, 3, 1); Copy(GetBytes(dValue.Hour), 0, baTime, 4, 1); Copy(GetBytes(dValue.Minute), 0, baTime, 5, 1); Copy(GetBytes(dValue.Second), 0, baTime, 6, 1); Copy(GetBytes(dValue.Millisecond), 0, baTime, 7, 2); // 0 to 999 millisecond. return baTime; }
Luckstar Binary DateTime
Item | Byte | Range | Storage |
---|---|---|---|
yyyy | 2 | 0-9999 |
8 Bytes |
MM | 1 | 1-12 |
4 Bytes |
dd | 1 | 1-31 |
2 Bytes |
HH | 1 | 0-23 |
1 Byte |
mm | 1 | minute | |
ss | 1 | 0-59 seconds | |
ff | 1 | 0-99 ( 10 milliseconds) |
XML DateTime
using System; using System.Xml.Linq; class Test { static void Main() { DateTime now = DateTime.Now; XElement element = new XElement("Now", now); Console.WriteLine(element); DateTime parsed = (DateTime) element; Console.WriteLine(parsed); } } Output: <Now>2011-01-21T06:24:12.7032222+00:00</Now> 21/01/2011 06:24:12
ISO8601 DateTime
class Test { static void Main() { DateTime dt = DateTime.Now; Console.WriteLine(string.Format("{0}Z", dt.ToString("s"))); Console.WriteLine(dt.ToString("o")); Console.WriteLine(dt.ToString(@"yyyy-MM-dd\THH:mm:ss\Z")); } } Output: 2011-01-21T06:24:12Z 2011-01-21T06:24:12.7032222Z 2011-01-21T06:24:12Z public static bool GetDateTimeFromStringISO8601(string sDateTime, out DateTime dOutput) { if (DateTime.TryParseExact(sDateTime, new string[] { @"yyyy-MM-dd\THH:mm:ss\Z", "o" } , CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal , out dOutput)) return true; else return false; } public static string ToStringISO8601(DateTime dInput) { // CodeHelper: //return string.Format("{0}Z", dInput.ToString("s")); //return dInput.ToString("o"); return dInput.ToString(@"yyyy-MM-dd\THH:mm:ss\Z"); // readable }
Data type | C# | Range | Storage |
---|---|---|---|
bigint | long |
-2^63 (-9,223,372,036,854,775,808) to 2^63-1
(9,223,372,036,854,775,807)
18位數字(只算足10進位數字的部分). |
8 Bytes |
int | int |
-2^31 (-2,147,483,648) to 2^31-1
(2,147,483,647) 9位數字(只算足10進位數字的部分). |
4 Bytes |
smallint | short |
-2^15 (-32,768) to 2^15-1 (32,767) 4位數字(只算足10進位數字的部分). |
2 Bytes |
tinyint | byte |
0 to 255 2位數字(只算足10進位數字的部分). |
1 Byte |
Copyright © 2010 京奇電腦 |
|