C#时间戳转时间-时间转时间戳

        /// <summary>
        /// 时间戳转为C#格式时间
        /// </summary>
        /// <param name=”timeStamp”></param>
        /// <param name="bflag">为真时获取10位时间戳,为假时获取13位时间戳.</param>
        /// <returns></returns>
        private DateTime GetTime(string timeStamp, bool bflag = true)
        {
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long lTime;
            if (bflag==true)
            {
                 lTime = long.Parse(timeStamp + "0000000");
            }
            else{
                 lTime = long.Parse(timeStamp + "0000");
            }

            TimeSpan toNow = new TimeSpan(lTime); return dtStart.Add(toNow);
        }
        /// <summary>
        /// 获取当前时间戳
        /// </summary>
        /// <param name="bflag">为真时获取10位时间戳,为假时获取13位时间戳.</param>
        /// <returns></returns>
        public static string GetTimeStamp(bool bflag = true)
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            string ret = string.Empty;
            if (bflag)
                ret = Convert.ToInt64(ts.TotalSeconds).ToString();
            else
                ret = Convert.ToInt64(ts.TotalMilliseconds).ToString();

            return ret;
        }
时间: 2024-08-02 19:45:11

C#时间戳转时间-时间转时间戳的相关文章

JS 时间字符串与时间戳之间的转换

1.当前时间换时间戳 var timestamp = parseInt(new Date().getTime()/1000); // 当前时间戳 document.write(timestamp); 2.当前时间换日期字符串 var now = new Date(); var yy = now.getFullYear(); //年 var mm = now.getMonth() + 1; //月 var dd = now.getDate(); //日 var hh = now.getHours(

js时间格式化工具,时间戳格式化,字符串转时间戳

在开发中经常会用到时间格式化,有时候在网上搜索一大堆但不是自己想要的,自己总结一下,写一个时间格式化工具方便以后直接使用,欢迎大家来吐槽-- 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

字符串时间转为时间戳,时间戳转为字符串时间

// 获取某个时间格式的时间戳 var stringTime = "2014-07-10 10:21:12"; var timestamp2 = Date.parse(new Date(stringTime)); timestamp2 = timestamp2 / 1000; //格式化时间戳 function ChangeDateFormat(val) { if (val != null) { var date = new Date(parseInt(val.replace(&quo

C#中 时间戳与普通时间格式的转换

时间戳,通常是一个字符序列,唯一地标识某一刻的时间. C#中关于时间戳与普通时间格式的相互转换如下 输出结果如下

用shell将时间字符串与时间戳互转

date的详细用户可以参考下面的 http://www.cnblogs.com/xd502djj/archive/2010/12/29/1919478.html date 的具体用法可以查看另外一篇博文 <shell date 命令详解>http://blog.csdn.net/runming918/article/details/7223520 date +%s   可以得到UNIX的时间戳;用shell将时间字符串与时间戳互转:      date -d "2010-10-18

JS时间戳比较大小:对于一组时间戳(开始时间~结束时间)和另一组时间戳进行比较,用于判断被比较时间戳组是否在要求范围内

/* *JS时间戳比较大小:对于一组时间戳(开始时间~结束时间)和另一组时间戳进行比较,用于判断被比较时间戳组是否在要求范围内 *@param date1 date2(形如:'2015-01-01'类型字符串) */ function compareDate(date1,date2){ //对获得的时间戳区间与既定的时间戳进行比对 var baseDate1='2015-01-01'; var baseDate2='2015-03-31'; baseDate1=new Date(baseDate

jQuery将时间转化为时间戳或将时间戳转化为时间

下面的这段代码,是可以将时间戳转为时间,或者将时间戳转为时间: <script type="text/javascript"> $.extend({ myTime:{ CurTime: function(){ return Date.parse(new Date())/1000; }, DateToUnix: function(string) { var f = string.split(' ', 2); var d = (f[0] ? f[0] : '').split('

时间转换为Unix时间戳

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Common { public class DateUtils { /// <summary> /// 时间转换为Unix时间戳 /// </summary> /// <param name="date"&g

mysql数据库时间戳与正常时间格式之间的转换

mysql时间转换成时间戳create_time between UNIX_TIMESTAMP('2015-11-20 00:00:00') and UNIX_TIMESTAMP('2015-11-20 23:59:59') 时间戳转换成yyyy-mm-dd格式FROM_UNIXTIME(create_time,'%Y-%m-%d') < '2015-11-12'

Erlang 日期和时间处理、时间戳转换

http://www.csdn 123.com/html/blogs/20131113/95993.htm 获取当前时间 erlang:now()得到的是从1970年1月1日零时起,到现在经过的时间,结果为{MegaSecs, Secs, MicroSecs}.有个问题要注意,还有另外一个函数可以实现同样的功能:os:timestamp() 那么erlang:now()和os:timestamp()的区别是什么? erlang的解释如下: erlang:now() If you do not n