• 文库
  • 字符
  • 转换
  • 加密
  • 网络
  • 更多
    图表
    数学
    坐标
    图片
    文件
  • 文库
    字符
    转换
    加密
    网络
    更多
    图表
    数学
    坐标
    图片
    文件
logo 在线工具大全
4 评论 收藏 复制链接 分享

Unix时间戳转换工具


Unix时间戳转换工具-工具简介

Unix时间戳和时间互转。Unix时间戳(英文为Unix epoch, Unix time, POSIX time 或 Unix timestamp)是从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒。

Unix时间戳转换工具-使用说明

UNIX时间戳在线转换工具,支持时间和UNIX时间戳的互相转换。时间显示本地时间(当前时区时间)和UTC时间。UNIX时间戳支持秒和毫秒单位。

  1. UNIX时间戳转换为时间:在时间戳输入框中填写待转换的时间戳,填写完以后,选择时间戳的单位。点击转换即可将Unix时间戳转换为时间。
  2. 时间转换为UNIX时间戳:在时间输入框中填写待转换时间,支持的时间格式为2022-01-10 19:21:592022-01-10 19:21:59.123, 填写完成以后,点击转换即可将时间转换为Unix时间戳。

编程语言中获取当前时间戳

编程语言 当前时间戳
Bash
date +%s
C
#include <stdio.h>
#include <time.h>

int main ()
{
    time_t seconds;

    seconds = time(NULL);
    printf("Seconds since January 1, 1970 = %ld\n", seconds);

    return(0);
}
C#
DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds
C++
#include <iostream>
#include <ctime>

int main()
{
    std::time_t t = std::time(0);  // t is an integer type
    std::cout << t << " seconds since 01-Jan-1970\n";
    return 0;
}
Dart
(new DateTime.now().millisecondsSinceEpoch / 1000).truncate()
Golang
import (
  "time"
)
int64(time.Now().Unix())
Groovy
(new Date().time / 1000).longValue()
Dart
(new DateTime.now().millisecondsSinceEpoch / 1000).truncate()
Java
System.currentTimeMillis() / 1000
JavaScript
Math.round(new Date() / 1000)
Kotlin
System.currentTimeMillis() / 1000
Lua
os.time()
MySQL
SELECT unix_timestamp(now())
Objective-C
[[NSDate date] timeIntervalSince1970]
Perl
$currentTimestamp = time()
PHP
<?php

time();
Python
import time
time.time()
Ruby
Time.now.to_i
Rust
use std::time::{SystemTime, UNIX_EPOCH};

match SystemTime::now().duration_since(UNIX_EPOCH) {
    Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
    Err(_) => panic!("SystemTime before UNIX EPOCH!"),
}
Scala
val now = new Date()
println(now.getTime)
SQLite
SELECT strftime('%s', 'now')
TypeScript
let timestamp = Date.parse(new Date().toString()) / 1000;
console.log('timestamp: ' + timestamp);