0

こんにちは、2 つの文字列があります。

entertime "2014-03-06T09:35:36Z" 
exittime "2014-03-06T09:38:36Z" 

この場合は 3 分を返す必要があります。

私の方法は次のようになります。

 boost::gregorian::date returnTime(std::string entertime, std::string exittime){
 boost::gregorian::date denter = boost::gregorian::from_string(entertime);
 boost::gregorian::date dexit = boost::gregorian::from_string(entertime);
 boost::gregorian::date dresult = dexit-denter;

この時差を取得する方法はありますか?

前もって感謝します!

4

1 に答える 1

1

残念ながら、特定のタイムスタンプの直接的なコンバーターはありません。すべての区切り文字を削除して、iso 仕様を満たす文字列を形成できる場合は、以下を実行できます。

  auto ts1 = boost::posix_time::from_iso_string("20140306T093536Z");
  auto ts2 = boost::posix_time::from_iso_string("20140306T093836Z");

  std::cout << (ts2 - ts1) << std::endl;

00:03:00これは、期待どおりに出力されるはずです。注 ここでの型は ( ts1&ts2boost::posix_time::ptimeあり、デルタは a ですboost::posix_time::time_duration)

于 2014-03-07T14:02:20.717 に答える