/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
public static string GetTimeSpan(System.DateTime time)
{
long ts = GetUnixTime(time);
return ts.ToString();
} /// <summary>
/// 将DateTime时间格式转换为Unix时间戳格式
/// </summary>
/// <param name="time">时间</param>
/// <returns>long</returns>
public static long GetUnixTime(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(, , , , , , ));
long t = (time.Ticks - startTime.Ticks) / ; //除10000调整为13位
return t;
}
/// <summary>
/// 将Unix时间戳转为C#时间格式
/// </summary>
/// <param name="timeSpan"></param>
/// <returns></returns>
public static DateTime GetDateTimeFromUnix(string timeSpan)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(, , ));
long lTime = long.Parse(timeSpan + "");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}

/// <summary>
/// 创建时间
/// </summary>
public string createTime { get; set; }

public DateTime _createTime {
get
{
if (string.IsNullOrEmpty(this.createTime))
return DateTime.MinValue;
return TimerTool.GetDate

 /// <summary>
/// 根据字节长度来截取字符串
/// </summary>
///<param name="origStr">原始字符串</param>
///<param name="length">提取前length个字节</param>
/// <returns></returns>
public static String CutByteString(string origStr, int length)
{
byte[] bytes = Encoding.Unicode.GetBytes(origStr);
int n = ; // 表示当前的字节数
int i = ; // 要截取的字节数
for (; i < bytes.GetLength() && n < length; i++)
{
// 偶数位置,如0、2、4等,为UCS2编码中两个字节的第一个字节
if (i % == )
{
n++; // 在UCS2第一个字节时n加1
}
else
{
// 当UCS2编码的第二个字节大于0时,该UCS2字符为汉字,一个汉字算两个字节
if (bytes[i] > )
{
n++;
}
}
}
// 如果i为奇数时,处理成偶数
if (i % == )
{
// 该UCS2字符是汉字时,去掉这个截一半的汉字 if (bytes[i] > )
i = i - ; // 该UCS2字符是字母或数字,则保留该字符
else
i = i + ;
}
return Encoding.Unicode.GetString(bytes, , i);
} var countlen = System.Text.Encoding.Default.GetByteCount(LocalDataManager.Instance.UserModel.student.name);
NameText.text = countlen > ? CutByteString(LocalDataManager.Instance.UserModel.student.name, ) : LocalDataManager.Instance.UserModel.student.name;

TimeFromUnix(this.createTime);
}
}

c#时间戳相互转换的更多相关文章

  1. js sql C#时间、时间戳相互转换

    js. sql. C#时间.时间戳相互转换 //1.获取当前时间戳_c# ) / //2.时间戳->时间 C# DateTime b11 = GetTime(");//11位时间戳-& ...

  2. iOS标准时间与时间戳相互转换

    iOS标准时间与时间戳相互转换 (2012-07-18 17:03:34) 转载▼ 标签: ios 时间戳 标准时间 格式 设置 转化 杂谈 分类: iPhone开发 设置时间显示格式:     NS ...

  3. 字符串时间与Unix时间戳相互转换

    字符串时间与Unix时间戳相互转换 /** * @Author: wangkun * @Date : 2016/1/21 13:43 * @Description : 字符串时间转换为Unix时间戳 ...

  4. python正常时间和unix时间戳相互转换的方法

    python正常时间和unix时间戳相互转换的方法 本文实例讲述了python正常时间和unix时间戳相互转换的方法.分享给大家供大家参考.具体分析如下: 这段代码可以用来转换常规时间格式为unix时 ...

  5. Python3 日期与时间戳相互转换

    开发中经常会对时间格式处理,对于时间数据,比如2019-02-28 10:23:29,有时需要日期与时间戳进行相互转换,在Python3中主要用到time模块,相关的函数如下: 其中unix_time ...

  6. jQuery添加添加时间与时间戳相互转换组件

    时间与时间戳的格式相互转换(转换主要兼容ie8,ie8不支持new Date()) (function($) { $.extend({ myTime: { CurTime: function () { ...

  7. MySQL时间戳相互转换

    mysql将时间戳转成常用时间格式 在mysql中,一个时间字段的存储类型是int(11),怎么转化成字符类型,比方存储为13270655222,需要转化为yyyy -mm-dd的形式. 使用 FRO ...

  8. iOS - 标准时间与时间戳相互转换

    做倒计时后台传的不是时间戳,是时间然后需要与系统时间对比得出时间戳进行倒计时显示 #pragma mark -- 倒计时 // 倒计时时间 NSString* timeStr = task.recei ...

  9. JS获取当前时间及时间戳相互转换

    1.获取当前时间的 时间戳 Date.parse(new Date()) 结果:1486347562000 2.获取当前 时间 new Date() 结果:Mon Feb 06 2017 10:19: ...

随机推荐

  1. Python 单线程下实现多个socket并发

    ## 客户端 import socket import gevent import threading import multiprocessing ip_bind = ('127.0.0.1',80 ...

  2. GHOST CMS - Package.json

    Package.json The package.json file is a set of meta data about a theme. package.json 文件是一组关于主题的元数据. ...

  3. swoole运行模式加速laravel应用的详细介绍

    本篇文章给大家带来的内容是关于swoole运行模式加速laravel应用的详细介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 一.Swoole Swoole号称重新定义了PHP, ...

  4. 一些实用的 Laravel 小技巧

    Laravel 中一些常用的小技巧,说不定你就用上了. 1.侧栏 网站一般都有侧栏,用来显示分类,标签,热门文章,热门评论啥的,但是这些侧栏都是相对独立的模块,如果在每一个引入侧栏的视图中都单独导入与 ...

  5. SpringBoot系列之集成logback实现日志打印(篇二)

    SpringBoot系列之集成logback实现日志打印(篇二) 基于上篇博客SpringBoot系列之集成logback实现日志打印(篇一)之后,再写一篇博客进行补充 logback是一款开源的日志 ...

  6. 详解EMC测试国家标准GB/T 17626

    电波暗室,用于模拟开阔场,同时用于辐射无线电骚扰(EMI)和辐射敏感度(EMS)测量的密闭屏蔽室. 来源:http://gememc.com/upload/201712/201712010930227 ...

  7. OpenWrite一款博客可一文多发的实用工具

    前言 许多网友想看一文多发的OpenWrite,今天,它来了!别问落地价,因为内测无价! 这款实用工具,可支持十大博客平台一键发布,是博主们的发文神器 你看它多种平台.一键管理.后台界面优雅.还有签到 ...

  8. CVPR 2019轨迹预测竞赛冠军方法总结

    背景 CVPR 2019 是机器视觉方向最重要的学术会议,本届大会共吸引了来自全世界各地共计 5160 篇论文,共接收 1294 篇论文,投稿数量和接受数量都创下了历史新高,其中与自动驾驶相关的论文. ...

  9. mysql与python的交互

    mysql是一种关系型数据库,是为了表示事物与事物之间的关系,本身存于数据库中的内容意义并不大,所以广泛应用于编程语言中,python中九含有与MySQL交互的模块 pymysql 编程对mysql的 ...

  10. 0基础-scp命令一学就会

    scp -P 22 -r  /home/server Android@192.168.1.110:/opt    将本地/home/server的文件夹上传到远端服务器192.168.1.110的目录 ...