OctetString 转String
2024-08-26 08:14:14
/// <summary>
/// OctetString转时间
/// </summary>
/// <param name="ss">字符串如 07 E3 06 06 11 10 0A 00 2B 08 00</param>
/// <returns>2012-09-23 17:01:27</returns>
public static string OctetString2DateAndTime(string ss)
{
// 07 E3 06 06 11 10 0A 00 2B 08 00
byte[] bts=ss.Trim().Split(' ').Select(s => byte.Parse(Convert.ToInt32("0x" + s, ).ToString())).ToArray();
byte[] format_str = new byte[]; //保存格式化过后的时间字符串
int year = bts[] * + bts[];
int month = bts[];
int day = bts[];
int hour = bts[];
int minute = bts[];
int second = bts[];
int msecond = bts[];
//以下为格式化字符串
int index = ;
int temp = year;
for (; index >= ; index--)
{
format_str[index] = (byte)( + (temp - temp / * ));
temp /= ;
} format_str[] = (byte)'-';
index = ;
temp = month;
for (; index >= ; index--)
{
format_str[index] = (byte)( + (temp - temp / * ));
temp /= ;
} format_str[] = (byte)'-';
index = ;
temp = day;
for (; index >= ; index--)
{
format_str[index] = (byte)( + (temp - temp / * ));
temp /= ;
} format_str[] = (byte)' ';
index = ;
temp = hour;
for (; index >= ; index--)
{
format_str[index] = (byte)( + (temp - temp / * ));
temp /= ;
} format_str[] = (byte)':';
index = ;
temp = minute;
for (; index >= ; index--)
{
format_str[index] = (byte)( + (temp - temp / * ));
temp /= ;
} format_str[] = (byte)':';
index = ;
temp = second;
for (; index >= ; index--)
{
format_str[index] = (byte)( + (temp - temp / * ));
temp /= ;
}
return Encoding.Default.GetString(format_str);
}
最新文章
- thinkphp 设计思想
- iOS ARC和MRC混编
- Java中获取完整的url
- php 燕十八 观察者模式代码例子
- 修改上一篇文章的node.js代码,支持默认页及支持中文
- JS 部分常见循环、分支、嵌套练习
- 用C语言实现Ping程序功能
- Oracle实验手册
- 【代码审计】五指CMS_v4.1.0 copyfrom.php 页面存在SQL注入漏洞分析
- cocos2dx 粒子系统
- nginx 执行理解
- 【Python】读取excel数据
- Docker一键部署Hadoop心得(一)
- iKcamp|基于Koa2搭建Node.js实战(含视频)☞ 视图Nunjucks
- Linux 设备模型之 (kobject、kset 和 Subsystem)(二)
- 【BZOJ4922】[Lydsy六月月赛]Karp-de-Chant Number 贪心+动态规划
- 中国大学MOOC-JAVA学习(浙大翁恺)—— 温度转换
- swoole http_server 多进程并使用多进程处理消息
- 【BZOJ5329】【SDOI2018】战略游戏(圆方树,虚树)
- 1.ubuntu的安装
热门文章
- Codes: MODERN ROBOTICS Ch.3_Expo. Coods.基础代码实现
- Systemweaver — 电子电气协同设计研发平台
- C++中与类有关的注意事项(更新中~~~)
- 《基于 Java EE 的高校重修管理系统设计与实现》论文笔记(九)
- 忘记 MySQL 的 root 帐号密码该怎么办
- 行为型模式(四) 观察者模式(Observer)
- docker 进程 转载:
- navcat导入mysql.sql出现:2006, &#39;MySQL server has gone away&#39;
- am335x system upgrade kernel can(八)
- Windows异常的分发处理流程