Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Date / Time Class

Date / Time Class

Scheduled Pinned Locked Moved C / C++ / MFC
toolsquestion
9 Posts 6 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mike Certini
    wrote on last edited by
    #1

    I need to find the best time class to use with a program that works with a date/time number in the following format: yyyy.mm.dd hh:mm:ss.ms. Essentially, I am reading values from a flat file (CSV) into a variable and then working with the variable. Does anyone out there know the best class to use? I have researched CFileTime and CTime classes. I do not know if functions within are the best for manipulating time. CTime has been ruled out because it does not accomodate milliseconds. Are there other classes I am not aware of? Lastly is there any references (links) showing how the functions are used. The overall application involves exporting the applicable function through a DLL into an MQL4 script.

    C _ C J L 5 Replies Last reply
    0
    • M Mike Certini

      I need to find the best time class to use with a program that works with a date/time number in the following format: yyyy.mm.dd hh:mm:ss.ms. Essentially, I am reading values from a flat file (CSV) into a variable and then working with the variable. Does anyone out there know the best class to use? I have researched CFileTime and CTime classes. I do not know if functions within are the best for manipulating time. CTime has been ruled out because it does not accomodate milliseconds. Are there other classes I am not aware of? Lastly is there any references (links) showing how the functions are used. The overall application involves exporting the applicable function through a DLL into an MQL4 script.

      C Offline
      C Offline
      Chandrasekharan P
      wrote on last edited by
      #2

      You need to make your own class for ms calculation. There is no ready made classes available for that.

      Every new day is another chance to change your life.

      1 Reply Last reply
      0
      • M Mike Certini

        I need to find the best time class to use with a program that works with a date/time number in the following format: yyyy.mm.dd hh:mm:ss.ms. Essentially, I am reading values from a flat file (CSV) into a variable and then working with the variable. Does anyone out there know the best class to use? I have researched CFileTime and CTime classes. I do not know if functions within are the best for manipulating time. CTime has been ruled out because it does not accomodate milliseconds. Are there other classes I am not aware of? Lastly is there any references (links) showing how the functions are used. The overall application involves exporting the applicable function through a DLL into an MQL4 script.

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        The COleDateTime Class[^] should work for you.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        1 Reply Last reply
        0
        • M Mike Certini

          I need to find the best time class to use with a program that works with a date/time number in the following format: yyyy.mm.dd hh:mm:ss.ms. Essentially, I am reading values from a flat file (CSV) into a variable and then working with the variable. Does anyone out there know the best class to use? I have researched CFileTime and CTime classes. I do not know if functions within are the best for manipulating time. CTime has been ruled out because it does not accomodate milliseconds. Are there other classes I am not aware of? Lastly is there any references (links) showing how the functions are used. The overall application involves exporting the applicable function through a DLL into an MQL4 script.

          C Offline
          C Offline
          Code o mat
          wrote on last edited by
          #4

          Don't know if it is available to you or not or that if it can do what you need or not but check out boost::date_time[^], maybe it can help.

          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

          1 Reply Last reply
          0
          • M Mike Certini

            I need to find the best time class to use with a program that works with a date/time number in the following format: yyyy.mm.dd hh:mm:ss.ms. Essentially, I am reading values from a flat file (CSV) into a variable and then working with the variable. Does anyone out there know the best class to use? I have researched CFileTime and CTime classes. I do not know if functions within are the best for manipulating time. CTime has been ruled out because it does not accomodate milliseconds. Are there other classes I am not aware of? Lastly is there any references (links) showing how the functions are used. The overall application involves exporting the applicable function through a DLL into an MQL4 script.

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            Mike Certini wrote:

            need to find the best time class to use with a program that works with a date/time number in the following format: yyyy.mm.dd hh:mm:ss.ms.

            As a note... That is a timestamp. Timestamps always have a timezone either implicitly or explicitly. So one should always figure out what the timezone is and how it is defined.

            1 Reply Last reply
            0
            • M Mike Certini

              I need to find the best time class to use with a program that works with a date/time number in the following format: yyyy.mm.dd hh:mm:ss.ms. Essentially, I am reading values from a flat file (CSV) into a variable and then working with the variable. Does anyone out there know the best class to use? I have researched CFileTime and CTime classes. I do not know if functions within are the best for manipulating time. CTime has been ruled out because it does not accomodate milliseconds. Are there other classes I am not aware of? Lastly is there any references (links) showing how the functions are used. The overall application involves exporting the applicable function through a DLL into an MQL4 script.

              L Offline
              L Offline
              loveheronly
              wrote on last edited by
              #6

              time_t curr_time = time(NULL); struct tm *pt = NULL; pt = localtime(&curr_time); char cTime[256],cTime1; sprintf(cTime,"%04d.%02d.%02d%02d:%02d:%02d",pt->tm_year+1900, pt->tm_mon+1, pt->tm_mday,pt->tm_hour,pt->tm_min,pt->tm_sec);

              M 2 Replies Last reply
              0
              • L loveheronly

                time_t curr_time = time(NULL); struct tm *pt = NULL; pt = localtime(&curr_time); char cTime[256],cTime1; sprintf(cTime,"%04d.%02d.%02d%02d:%02d:%02d",pt->tm_year+1900, pt->tm_mon+1, pt->tm_mday,pt->tm_hour,pt->tm_min,pt->tm_sec);

                M Offline
                M Offline
                Mike Certini
                wrote on last edited by
                #7

                loveheronly, Excellent, thank you for your reply. Does the time_t container accomodate milliseconds?

                1 Reply Last reply
                0
                • L loveheronly

                  time_t curr_time = time(NULL); struct tm *pt = NULL; pt = localtime(&curr_time); char cTime[256],cTime1; sprintf(cTime,"%04d.%02d.%02d%02d:%02d:%02d",pt->tm_year+1900, pt->tm_mon+1, pt->tm_mday,pt->tm_hour,pt->tm_min,pt->tm_sec);

                  M Offline
                  M Offline
                  Mike Certini
                  wrote on last edited by
                  #8

                  After considerable research I have come up with the following solution which is 95% complete. I though cannot figure out how to report the milliseconds.

                  #include #using using namespace System;
                  using namespace System::Globalization;
                  using System::String;

                  int main()
                  {
                  // Assume the current culture is en-US.
                  // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds and 253 milliseconds.

                  String\* myDateTimeValue = S"02/16/1992 12:15:12.253";
                  String\* expectedFormats\[\] = {S"MM/dd/yyyy hh:mm:ss.FFF"};
                  IFormatProvider\* culture = new CultureInfo(S"en-US", true);
                  DateTime myDateTime = DateTime::ParseExact(myDateTimeValue, expectedFormats, culture, DateTimeStyles::AssumeLocal);
                  Console::WriteLine(S"1) myDateTime       = {0}", \_\_box(myDateTime));
                  
                  system("pause");
                  }
                  
                  L 1 Reply Last reply
                  0
                  • M Mike Certini

                    After considerable research I have come up with the following solution which is 95% complete. I though cannot figure out how to report the milliseconds.

                    #include #using using namespace System;
                    using namespace System::Globalization;
                    using System::String;

                    int main()
                    {
                    // Assume the current culture is en-US.
                    // The date is Feburary 16, 1992, 12 hours, 15 minutes and 12 seconds and 253 milliseconds.

                    String\* myDateTimeValue = S"02/16/1992 12:15:12.253";
                    String\* expectedFormats\[\] = {S"MM/dd/yyyy hh:mm:ss.FFF"};
                    IFormatProvider\* culture = new CultureInfo(S"en-US", true);
                    DateTime myDateTime = DateTime::ParseExact(myDateTimeValue, expectedFormats, culture, DateTimeStyles::AssumeLocal);
                    Console::WriteLine(S"1) myDateTime       = {0}", \_\_box(myDateTime));
                    
                    system("pause");
                    }
                    
                    L Offline
                    L Offline
                    loveheronly
                    wrote on last edited by
                    #9

                    #include <time.h>

                    clock_t start=clock();

                    //...

                    clock_t end=clock();

                    unsigned int dis_time=end-start;

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups