const nowMs = Date.now();
const nowSec = Math.floor(Date.now() / 1000);
const fromTs = new Date(1728192000000);
const toTsMs = Date.parse('2025-01-01T00:00:00Z');
import time, datetime
now_ms = int(time.time() * 1000)
now_s = int(time.time())
dt = datetime.datetime.fromtimestamp(1728192000, tz=datetime.timezone.utc)
long nowMs = System.currentTimeMillis();
long nowSec = nowMs / 1000;
Instant instant = Instant.ofEpochMilli(1728192000000L);
ZonedDateTime zdt = instant.atZone(ZoneId.of("UTC"));
$nowMs = (int) (microtime(true) * 1000);
$nowSec = time();
$dt = (new DateTime('@1728192000'))->setTimezone(new DateTimeZone('UTC'));
nowMs := time.Now().UnixMilli()
nowSec := time.Now().Unix()
dt := time.UnixMilli(1728192000000).In(time.UTC)
now_ms = (Time.now.to_f * 1000).to_i
now_s = Time.now.to_i
dt = Time.at(1728192000).utc
#
/* C:获取当前时间(毫秒)并转换为日期 */
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
long long now_ms() {
struct timeval tv; gettimeofday(&tv, NULL);
return (long long)tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
int main(){
long long ms = now_ms();
time_t s = ms / 1000;
struct tm tm = *gmtime(&s);
char buf[64];
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
printf("now_ms=%lld now=%s UTC\n", ms, buf);
return 0;
}
#
// C++:获取当前时间戳并格式化
#include <iostream>
#include <iomanip>
#include <chrono>
#include <ctime>
int main(){
using namespace std::chrono;
auto now = system_clock::now();
auto ms = duration_cast(now.time_since_epoch()).count();
std::time_t t = ms/1000;
std::tm tm = *std::gmtime(&t);
std::cout << "nowMs=" << ms << "\n";
std::cout << std::put_time(&tm, "%Y-%m-%d %H:%M:%S") << " UTC\n";
return 0;
}
// Kotlin:当前时间戳及 Instant 示例
import java.time.Instant
import java.time.ZoneId
fun main(){
val nowMs = System.currentTimeMillis()
val nowSec = nowMs / 1000
println("nowMs=$nowMs")
println("nowSec=$nowSec")
val inst = Instant.ofEpochMilli(1728192000000)
println(Instant.ofEpochMilli(nowMs).atZone(ZoneId.of("UTC")))
}