/* C: get current time in ms and convert to date */
#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++: current timestamp and formatting
#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: current timestamp and Instant examples
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")))
}