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. Managed C++/CLI
  4. Convert to datetime problem

Convert to datetime problem

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
9 Posts 3 Posters 0 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.
  • W Offline
    W Offline
    wael_r
    wrote on last edited by
    #1

    i'm using window forms application and i'm facing a problem with a variable date_time that hold a long value 1243930978 I need to convert this number to datetime Note : when i declare the variable as "CTime sss" it give error undeclared identifier "sss" any one can help?

    W L G 3 Replies Last reply
    0
    • W wael_r

      i'm using window forms application and i'm facing a problem with a variable date_time that hold a long value 1243930978 I need to convert this number to datetime Note : when i declare the variable as "CTime sss" it give error undeclared identifier "sss" any one can help?

      W Offline
      W Offline
      wael_r
      wrote on last edited by
      #2

      Can any one help

      1 Reply Last reply
      0
      • W wael_r

        i'm using window forms application and i'm facing a problem with a variable date_time that hold a long value 1243930978 I need to convert this number to datetime Note : when i declare the variable as "CTime sss" it give error undeclared identifier "sss" any one can help?

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, this forum is about C++/CLI, that's the managed C++ dialect, part of .NET it has a very nice DateTime class with some constructors, and useful methods such as Parse() and TryParse(). AFAIK there is no CTime in its universe. Are you in the right forum? for plain C/C++ and MFC use the appropriate forum! :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        1 Reply Last reply
        0
        • W wael_r

          i'm using window forms application and i'm facing a problem with a variable date_time that hold a long value 1243930978 I need to convert this number to datetime Note : when i declare the variable as "CTime sss" it give error undeclared identifier "sss" any one can help?

          G Offline
          G Offline
          George L Jackson
          wrote on last edited by
          #4

          The value, 1243930978, is calculated from the number of seconds from 1/1/1970. To convert to a DateTime, you must account for this offset:

          DateTime time_offset(1970, 1, 1);
          DateTime time_converted = time_offset.AddSeconds(1243930978);

          "We make a living by what we get, we make a life by what we give." --Winston Churchill

          modified on Wednesday, June 3, 2009 4:36 PM

          W 1 Reply Last reply
          0
          • G George L Jackson

            The value, 1243930978, is calculated from the number of seconds from 1/1/1970. To convert to a DateTime, you must account for this offset:

            DateTime time_offset(1970, 1, 1);
            DateTime time_converted = time_offset.AddSeconds(1243930978);

            "We make a living by what we get, we make a life by what we give." --Winston Churchill

            modified on Wednesday, June 3, 2009 4:36 PM

            W Offline
            W Offline
            wael_r
            wrote on last edited by
            #5

            Thank you very much, i want you to know that i spend 2 days on this. and now you gave me the right answer Thankkkkkkkkk youuuuuuuuuuuuuuuuuu. i tried it works it gave me 3 hours difference and i handle it by adding 10800 sec to the number. but why it gave me difference 3 hours?

            G 1 Reply Last reply
            0
            • W wael_r

              Thank you very much, i want you to know that i spend 2 days on this. and now you gave me the right answer Thankkkkkkkkk youuuuuuuuuuuuuuuuuu. i tried it works it gave me 3 hours difference and i handle it by adding 10800 sec to the number. but why it gave me difference 3 hours?

              G Offline
              G Offline
              George L Jackson
              wrote on last edited by
              #6

              If the value was created on computer in local time EST, and it was converted on a computer in local time PST, you will have a 3 hour difference. You should use coordinated universal time (UTC) and adjust the time according to the local time of the computer. .NET has DateTime.UtcNow and DateTime.ToUniversalTime and C/C++ has gmtime.

              "We make a living by what we get, we make a life by what we give." --Winston Churchill

              modified on Thursday, June 4, 2009 8:02 AM

              W 1 Reply Last reply
              0
              • G George L Jackson

                If the value was created on computer in local time EST, and it was converted on a computer in local time PST, you will have a 3 hour difference. You should use coordinated universal time (UTC) and adjust the time according to the local time of the computer. .NET has DateTime.UtcNow and DateTime.ToUniversalTime and C/C++ has gmtime.

                "We make a living by what we get, we make a life by what we give." --Winston Churchill

                modified on Thursday, June 4, 2009 8:02 AM

                W Offline
                W Offline
                wael_r
                wrote on last edited by
                #7

                Please can you give me exactly how to use this function in the code?

                G 1 Reply Last reply
                0
                • W wael_r

                  Please can you give me exactly how to use this function in the code?

                  G Offline
                  G Offline
                  George L Jackson
                  wrote on last edited by
                  #8

                  Which function you need an example for? If you are using .NET 3.5, you can use the DateTimeOffset structure: .[^][^]. Examples for DateTime.ToUniversalTime method: http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx[^]. DateTime.UtcNow works like DateTime.Now: http://msdn.microsoft.com/en-us/library/system.datetime.utcnow.aspx[^]. gmtime: http://msdn.microsoft.com/en-us/library/0z9czt0w.aspx[^]. And, _mkgmtime: http://msdn.microsoft.com/en-us/library/2093ets1.aspx[^].

                  "We make a living by what we get, we make a life by what we give." --Winston Churchill

                  W 1 Reply Last reply
                  0
                  • G George L Jackson

                    Which function you need an example for? If you are using .NET 3.5, you can use the DateTimeOffset structure: .[^][^]. Examples for DateTime.ToUniversalTime method: http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx[^]. DateTime.UtcNow works like DateTime.Now: http://msdn.microsoft.com/en-us/library/system.datetime.utcnow.aspx[^]. gmtime: http://msdn.microsoft.com/en-us/library/0z9czt0w.aspx[^]. And, _mkgmtime: http://msdn.microsoft.com/en-us/library/2093ets1.aspx[^].

                    "We make a living by what we get, we make a life by what we give." --Winston Churchill

                    W Offline
                    W Offline
                    wael_r
                    wrote on last edited by
                    #9

                    Thanks it works fine. with UtcNow

                    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