Convert to datetime problem
-
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?
-
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?
-
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?
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.
-
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?
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
-
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
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?
-
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?
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
andDateTime.ToUniversalTime
and C/C++ hasgmtime
."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
-
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
andDateTime.ToUniversalTime
and C/C++ hasgmtime
."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
-
Which function you need an example for? If you are using .NET 3.5, you can use the
DateTimeOffset
structure: .[^][^]. Examples forDateTime.ToUniversalTime
method: http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx[^].DateTime.UtcNow
works likeDateTime.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
-
Which function you need an example for? If you are using .NET 3.5, you can use the
DateTimeOffset
structure: .[^][^]. Examples forDateTime.ToUniversalTime
method: http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx[^].DateTime.UtcNow
works likeDateTime.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