var str = 'Jan 23, 2019 10:25:47 AM';
var strnow = new Date(str);

时间戳(timestamp),一个能表示一份数据在某个特定时间之前已经存在的、 完整的、 可验证的数据,通常是一个字符序列,唯一地标识某一刻的时间。使用数字签名技术产生的数据, 签名的对象包括了原始文件信息、 签名参数、 签名时间等信息。广泛的运用在知识产权保护、 合同签字、 金融帐务、 电子报价投标、 股票交易等方面。

时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。通俗的讲, 时间戳是一份能够表示一份数据在一个特定时间点已经存在的完整的可验证的数据。 它的提出主要是为用户提供一份电子证据, 以证明用户的某些数据的产生时间。 在实际应用上, 它可以使用在包括电子商务、 金融活动的各个方面, 尤其可以用来支撑公开密钥基础设施的 “不可否认” 服务。

C# 如何生成一个时间戳

 
1
2
3
4
5
6
7
8
9
/// <summary> 
/// 获取时间戳 
/// </summary> 
/// <returns></returns> 
public static string GetTimeStamp() 
    TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); 
    return Convert.ToInt64(ts.TotalSeconds).ToString(); 

经常发现很多地方使用一个时间戳表示时间。比如: 1370838759  表示 2013年6月10日 12:32:39。 我们就需要一个工具,方便地转换这种时间格式

什么是时间戳?

时间戳, 又叫Unix Stamp. 从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒。

C# 时间戳转换为普通时间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 时间戳转为C#格式时间
        private DateTime StampToDateTime(string timeStamp)
        {
            DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long lTime = long.Parse(timeStamp + "0000000");
            TimeSpan toNow = new TimeSpan(lTime);
             
            return dateTimeStart.Add(toNow);
        }
 
        // DateTime时间格式转换为Unix时间戳格式
        private int DateTimeToStamp(System.DateTime time)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
            return (int)(time - startTime).TotalSeconds;
        }

  

 

相差格林威治时间 8个小时  中国是北京时间

var drtr = new DateTime(1970, 1, 1);
var sdsdsds = drtr.AddMilliseconds(1548210647000);
Console.WriteLine(sdsdsds);

DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse("1548210647" + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
var datepar = dateTimeStart.Add(toNow);
Console.WriteLine(datepar);
Console.WriteLine("----");

strnow.setMinutes(strnow.getMinutes()+1);

// strnow加上一分钟   返回时间的 时间戳

var str = 'Jan 23, 2019 10:25:47 AM';
var strnow = new Date(str);

js 取得当天0点 / 23:59:59 时间

 

js 取得今天0点:

const start = new Date(new Date(new Date().toLocaleDateString()).getTime());
console.log(start); //Mon Dec 04 2017 00:00:00 GMT+0800 (中国标准时间)

同理算出:

js 取得今天 23:59:59

const start = new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60*1000-1);
console.log(start); //Mon Dec 04 2017 23:59:59 GMT+0800 (中国标准时间)

其他也是同理类推

1 时间戳 2 C# 如何生成一个时间戳 3 js 时间加一分钟... 4 js string->date 5 js 取得当天0点 / 23:59:59 时间的更多相关文章

  1. C# 如何生成一个时间戳

    在程序中,常常会用到时间戳,如何生成一个时间戳呢? /// <summary> /// 获取时间戳 /// </summary> /// <returns>< ...

  2. js生成一个不重复的ID的函数的进化之路

    在MongoDB中的ObjectID,可以理解为是一个不会重复的ID,这里有个链接http://blog.csdn.net/xiamizy/article/details/41521025感兴趣可以去 ...

  3. js 如何生成一个不重复的ID的函数

    在MongoDB中的ObjectID,可以理解为是一个不会重复的ID,这里有个链接http://www.jb51.net/article/101164.htm感兴趣可以去研究一下. 我今天要做的就是做 ...

  4. JavaScript生成一个不重复的ID

    /** * 生成一个用不重复的ID */ function GenNonDuplicateID():String{ } 先看看下面的几个方法 1.生成[0,1)的随机数的Math.random,例如 ...

  5. PHP生成一个六位数的邀请码

    PHP生成一个六位数的邀请码 $unique_no = substr(base_convert(md5(uniqid(md5(microtime(true)),true)), 16, 10), 0, ...

  6. 【高性能】生成唯一时间戳ID,1毫秒预计能生成1000个

    凡事涉及到高性能貌似都是高大上的东西,所以嘛我也试试:其实这个时间戳ID的生成主要为了解决我们公司内部的券号生成,估计有小伙伴认为券号生成有这么麻烦嘛,搞个自增ID完全可以用起来,或者时间取毫微米时间 ...

  7. php生成毫秒时间戳的例子

    php时间函数time()生成当前时间的秒数,但是在一些情况下我们需要获取当前服务器时间和GMT(格林威治时间)1970年1月0时0分0秒的毫秒数,与Java中的currentTimeMilis()函 ...

  8. php获取一个月前的时间戳,获取三个月前的时间戳,获取一年前的时间戳

    strtotime 非常强大的一个获取时间戳的函数 php获取一个月前的时间戳: strtotime("-0 year -1 month -0 day"); php获取三个月前的时 ...

  9. js后端返回一个时间戳,用原生怎么对时间进行格式化?

    function fn(time) { var date = new Date(time); var len = time.toString().length; // 时间戳不足13位则在后面加零 i ...

随机推荐

  1. Springmvc 服务器端文件下载

    转自:http://blog.csdn.net/boneix/article/details/51303280 业务场景:点击下载后直接保存而不是打开 解决代码:前端传入url /** * 返回流 * ...

  2. Python操作MongoDB(PyMongo模块的使用)

    #!/usr/bin/env python #coding:utf-8 # Author:   --<qingfengkuyu> # Purpose: MongoDB的使用 # Creat ...

  3. powerdesigner 不显示表字段只显示表名

    在空白的地方右键选择 Display Preferences然后在左边的General Settings里选Table然后把Columns 的All Columns勾上 如果能帮上您,请选为满意答案, ...

  4. 【树莓派】树莓派上面安装配置teamviewer

    访问树莓派桌面,的另一种方式,就是使用Teamviewer. 参考这篇文章做了实验:http://www.linuxdiyf.com/linux/16887.html,对其中部分进行了件要整理和总结. ...

  5. Jenkins 持续集成综合实战

    Jenkins 是一款流行的开源持续集成(Continuous Integration)工具,广泛用于项目开发,具有自动化构建.测试和部署等功能.本文以 CentOS7 环境为例,总结了 Jenkin ...

  6. MongoDB副本集配置系列五:副本集的在线迁移

    MongoDB副本集的在线迁移 查看当前集群的状态: { "setName" : "gechongrepl", "setVersion" : ...

  7. 写带有清晰图片的博客:如何将word中的图片复制到windows live writer保持大小不变--清晰度不变

    写blog的习惯,先在word写了,复制到windows live writer,再发布到博客园.word中的文章,图片有缩放比例,复制到windows live writer后图片变得不清晰.除了一 ...

  8. HotSpot JVM Component

  9. SpringBoot配置RestTemplate的代理和超时时间

    application.properties: #代理设置 proxy.enabled=false proxy.host=192.168.18.233 proxy.port=8888 #REST超时配 ...

  10. 基于py3和pymysql查询某时间段的数据

    #python3 #xiaodeng #基于py3和pymysql查询某时间段的数据 import pymysql conn=pymysql.connect(user='root',passwd='r ...