ブーストライブラリを使用して現在の時間をミリ秒単位で取得しようとしています.以下は、現在の時間をミリ秒単位で取得するために使用しているコードです。
boost::posix_time::ptime time = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_duration duration( time.time_of_day() );
std::cout << duration.total_milliseconds() << std::endl;
uint64_t timestampInMilliseconds = duration.total_milliseconds() // will this work or not?
std::cout << timestampInMilliseconds << std::endl;
しかし、これは10桁で出力され17227676
ます..私は自分のコードをubuntuマシンで実行しています..そして、それは常に13桁の長さの値だと思いますか? そうじゃない?
タイムスタンプをミリ秒単位で計算した後、以下の式を使用する必要があります-
int end = (timestampInMilliseconds / (60 * 60 * 1000 * 24)) % 14
しかし、どういうわけか、取得しているtimestampInMillisecondsが正しいかどうかわかりませんか?
まず、boost::posix を使用する必要がありますか? 私はいくつかのより良い方法があるかもしれないと仮定しています..私は自分のubuntuマシンでコードを実行しています..
アップデート:-
このbashスクリプトは、13桁のtimestampInMillisecondsを出力するため..
date +%s%N | cut -b1-13