DateTime库和日期间隔放置

发布于 2025-01-29 10:31:08 字数 1826 浏览 2 评论 0原文

这更多是一个一般理论问题,但我认为我应该给予一些背景。

我正在编写程序中间。基本要旨是我有2个DAT文件。在filea.dat中,每行是格式的时间戳yyyy-mm-dd hh:mm:ss和一些数据。在fileb.dat中,每行是格式DD-MM-YY HH:MM:SS的两个时间戳。

这个想法是该程序将创建更多的DAT文件,一个文件与Fileb.dat中的每个对相对应。每当filea.dat中的一条线的时间戳从fileb.dat的两个时间戳之间降落时,filea.dat的整行都将写入与配对板相对应的新的dat文件。有意义吗?

除了时间戳如何使用不同格式的情况下,该程序没有疯狂的程序。我刚刚听说有一种方法可以处理此操作,而不必使用我不知道的固有的C ++库“重新发明轮子”。

好奇地了解更多。

-J

编辑: - 最终没有学习任何对我的项目有用的东西,也许我只是没有得到它。我不知道。我知道的是我尝试了一些测试代码。

#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <tuple>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <complex>
#include <stdint.h>
#include <time.h>
#include <string.h>
#include <algorithm>

int main(){

  // Read from jet_full [C - (Date, Time), Data] - Cycle
  std::ifstream FullFile;
  FullFile.open("jet_full.txt");
  if(!FullFile)
    {
      std::cout << "Error opening file. \n";
      std::cout << "It may not exist where indicated" << std::endl;
      return 1;
    }
  
  int run = 0;
  int a, b ; 
  while(!FullFile.eof()){
    FullFile >> a >> b ;
    run++;
    std::cout << a << " " << b << " " << run << std::endl;
  // Create jet_run_XXX.dat
  //  ofstream runsplit;
  //  runsplit.open("jet_run_" >> run >> ".txt");
    
  // Read from jet_run_times.dat [A - (Date, Time), B - (Date, Time)] - Cycle
  // Check if A < C and C < B
  // If yes, write [C - (Date, Time), Data] to jet_run_XXX.dat
  // Cycle through all jet_run_times.dat
  // Cycle through all jet_full
    
  }
  return 0;
}  

输出是越来越多的行,所有读过,

0 0 [Run Number] 

我不明白为什么我只是在尝试阅读每个线文件的双重时间邮票时才能得到零。任何帮助将不胜感激。

This is more of a general theory question but I figure I should give some context anyway.

I'm in the middle of writing a program. The basic gist is that I have 2 dat files. In fileA.dat each line is a timestamp in the format YYYY-MM-DD HH:MM:SS and a bit of data. In fileB.dat each line is two timestamps in the format DD-MM-YY HH:MM:SS.

The idea is that the program will create a bunch more dat files, one corresponding to each pair from fileB.dat. Whenever the timestamp from a line in fileA.dat lands between the two timestamps of a pair line from fileB.dat, the whole line from fileA.dat will be written to the new dat file corresponding to the pair-stamps. Makes sense?

Nothing crazy about the program save maybe how the timestamps use different formats. I just heard there's a way to handle this without having to "reinvent the wheel" using inherent c++ library that I don't know about.

Curious to know more.

-J

Edit:- Didn't end up learning anything that actually seemed useful for my project, maybe I'm just not getting it. I don't know. What I do know is that I tried some test code.

#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <tuple>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <complex>
#include <stdint.h>
#include <time.h>
#include <string.h>
#include <algorithm>

int main(){

  // Read from jet_full [C - (Date, Time), Data] - Cycle
  std::ifstream FullFile;
  FullFile.open("jet_full.txt");
  if(!FullFile)
    {
      std::cout << "Error opening file. \n";
      std::cout << "It may not exist where indicated" << std::endl;
      return 1;
    }
  
  int run = 0;
  int a, b ; 
  while(!FullFile.eof()){
    FullFile >> a >> b ;
    run++;
    std::cout << a << " " << b << " " << run << std::endl;
  // Create jet_run_XXX.dat
  //  ofstream runsplit;
  //  runsplit.open("jet_run_" >> run >> ".txt");
    
  // Read from jet_run_times.dat [A - (Date, Time), B - (Date, Time)] - Cycle
  // Check if A < C and C < B
  // If yes, write [C - (Date, Time), Data] to jet_run_XXX.dat
  // Cycle through all jet_run_times.dat
  // Cycle through all jet_full
    
  }
  return 0;
}  

And the output is an ever growing number of lines that all read

0 0 [Run Number] 

I don't understand why I'm only getting Zeros when I'm trying to read the double time stamps per line file. Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文