前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在线Unix时间戳转换,在编程语言中获取Unix时间戳:

在线Unix时间戳转换,在编程语言中获取Unix时间戳:

原创
作者头像
vivec
修改2019-08-20 14:40:32
4K0
修改2019-08-20 14:40:32
举报
文章被收录于专栏:oktoolsoktools

在线Unix时间戳转换工具: https://oktools.net/timestamp

语言

毫秒

JavaScript

Math.round(new Date() / 1000)

new Date().getTime()

Java

System.currentTimeMillis() / 1000

System.currentTimeMillis()

Python

int(time.time())

int(time.time() * 1000)

Go

time.Now().Unix()

time.Now().UnixNano() / 1e6

PHP

time()

(int)(microtime(true) * 1000)

Ruby

Time.now.to_i

(Time.now.to_f * 1000).to_i

C#

DateTimeOffset.UtcNow.ToUnixTimeSeconds()

DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()

Swift

NSDate().timeIntervalSince1970

NSDate().timeIntervalSince1970 * 1000

Objective-C

NSDate date timeIntervalSince1970

NSDate date timeIntervalSince1970 * 1000

JS日期格式化显示 'yyyy-MM-dd hh:mm:ss'

代码语言:txt
复制
const dateFormat = 'yyyy-MM-dd hh:mm:ss';

Date.prototype.format = function (fmt) {
    let o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "s": this.getMilliseconds()
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (let k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};

效果

image.png
image.png

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 在线Unix时间戳转换工具: https://oktools.net/timestamp
    • JS日期格式化显示 'yyyy-MM-dd hh:mm:ss'
      • 效果
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档