#include <iostream>
#include <sys/time.h>
#include <cmath>
using std::cout; using std::endl;
int main() {
struct timeval ima;
time_t ut, ut0, ut8;
struct tm t;
struct tm t0 = { 0, 0, 9, 1, 0, 70, -1 };
struct tm t8 = { 7, 14, 12, 18, 0, 123, -1 };
//現在時刻の取得(msec)
gettimeofday(&ima, nullptr);
time_t mnow = (ima.tv_sec * 1000) + (ima.tv_usec / 1000);
cout << " msec since epoch: " << mnow << endl << endl;
//UNIX時間へ変換
ut = time(nullptr);
cout << " unixtime: " << ut << endl;
//年月日時刻へ変換
cout << " day-time: " << ctime(&ut) << endl;
//UNIX基準時(JST)
ut0 = mktime(&t0); // ut0 = 0
cout << " unixtime: " << ut0 << endl;
cout << " day-time: " << ctime(&ut0) << endl;
//2038年問題(JST)
ut8 = mktime(&t8); // ut8 = 2^31-1
cout << " unixtime: " << ut8 << endl;
cout << " dat-time: " << ctime(&ut8) << endl;
return EXIT_SUCCESS;
}
#! /usr/bin/swift
import Foundation
//現在時刻の取得(msec)
let date: Date = Date()
let unixtime: Int64 = Int64(date.timeIntervalSince1970)
let utime_ms: Int64 = Int64(date.timeIntervalSince1970*1000)
print(utime_ms)
//UNIX時間へ変換
var time = TimeInterval(integerLiteral: unixtime)
print(time)
//年月日時分秒へ変換(GMT)
var day = Date(timeIntervalSince1970: time)
print(day)
//UNIX基準時(GMT)
var zt = Int64(0)
var ut = TimeInterval(integerLiteral: zt)
var ud = Date(timeIntervalSince1970: ut)
print(ut)
print(ud)
//2038年問題(GMT)
zt = Int64(pow(2,Double(31)))-1
ut = TimeInterval(integerLiteral: zt)
ud = Date(timeIntervalSince1970: ut)
print(ut)
print(ud)
0 件のコメント:
コメントを投稿