/// <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. 《Dotnet9》建站-建站20天感悟

    时间如流水,只能流去不流回! 点赞再看,养成习惯,这是您给我创作的动力! 本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform.W ...

  2. 【搞定Jvm面试】 面试官:谈谈 JVM 类加载过程是怎样的?

    类加载过程 Class 文件需要加载到虚拟机中之后才能运行和使用,那么虚拟机是如何加载这些 Class 文件呢? 系统加载 Class 类型的文件主要三步:加载->连接->初始化.连接过程 ...

  3. WinForm WebBrowser 设置cookie

    [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)] public static exte ...

  4. C# ling to sql 左表连接

    var begin_daily = from a in _postgreDbContext.tab1 join b in _postgreDbContext.tab2 on a.id equals b ...

  5. threejs 限制物件只能在指定平面上拖拽

    threejs提供有 DragController.js的例子来辅助拖拽 该例子可以在基于当前屏幕的x和y轴上拖拽物体,但是它不能影响z轴. 查看代码,可以在touchStart\mousedown下 ...

  6. Dynamic Code Evaluation:Code Injection 动态代码评估:代码注入

  7. 一起学Spring之AOP

    概述 在软件开发中,我们重点关注的是业务逻辑代码,但在实际开发中,需要写的代码却不仅仅是业务逻辑,还需要处理记录日志,异常处理,事务控制等一些与业务无关的事情.而且这些代码也是服务端必须的,类似这样的 ...

  8. Python-根据照片信息获取用户详细信息(微信发原图或泄露位置信息)

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 蒙娜丽胖 PS:如有需要Python学习资料的小伙伴可以加点击下方 ...

  9. JavaScript 递归遍历json串获取相关数据

    递归遍历json串获取相关数据   by:授客 QQ:1033553122 1.   测试数据 // 导航菜单 [ { id: 1, parentId: 0, parentName: null, na ...

  10. DOMContentLoaded vs jQuery.ready vs onload, How To Decide When Your Code Should Run

    At a Glance Script tags have access to any element which appears before them in the HTML. jQuery.rea ...