473,811 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert time_t to System::DateTim e ???

I need to convert time_t to System::DateTim e. All of the examples that
I found are either in C# or in the obsolete managed C++ syntax. What
is the current syntax for converting a (probably 64 bit) time_t value
to System::DateTim e ???
Sep 22 '08 #1
4 5880

"PeteOlcott " <Pe********@gma il.comwrote in message
news:3e******** *************** ***********@m3g 2000hsc.googleg roups.com...
I need to convert time_t to System::DateTim e. All of the examples that
I found are either in C# or in the obsolete managed C++ syntax. What
is the current syntax for converting a (probably 64 bit) time_t value
to System::DateTim e ???

time_t t = ...;
long long filetime = t * 10000000LL + 116444736000000 000LL;
DateTime datetime = DateTime::FromF ileTimeUtc(file time);
Console::WriteL ine(datetime.To String());

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++
Sep 22 '08 #2
Here's my source, BTW:

Converting a time_t Value to a File Time
http://msdn.microsoft.com/en-us/libr...28(VS.85).aspx
Mark

--
Mark Salsbery
Microsoft MVP - Visual C++

Sep 22 '08 #3
On Sep 22, 5:45*pm, "Mark Salsbery [MVP]"
<MarkSalsbery[MVP]@newsgroup.nosp amwrote:
Here's my source, BTW:

Converting a time_t Value to a File Timehttp://msdn.microsoft. com/en-us/library/ms724228(VS.85) .aspx

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++
Here is the answer that I derived:

System::DateTim e time_tToSystemD ateTime(time_t tt)
{
tm* timeptr = gmtime(&tt);
DateTime sdt(timeptr->tm_year + 1900, timeptr->tm_mon + 1, timeptr-
>tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
return sdt;
}

Sep 23 '08 #4
On Sep 22, 7:06*pm, PeteOlcott <PeteOlc...@gma il.comwrote:
On Sep 22, 5:45*pm, "Mark Salsbery [MVP]"

<MarkSalsbery[MVP]@newsgroup.nosp amwrote:
Here's my source, BTW:
Converting a time_t Value to a File Timehttp://msdn.microsoft. com/en-us/library/ms724228(VS.85) .aspx
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++

Here is the answer that I derived:

System::DateTim e time_tToSystemD ateTime(time_t tt)
{
* tm* timeptr = gmtime(&tt);
* DateTime sdt(timeptr->tm_year + 1900, timeptr->tm_mon + 1, timeptr-
tm_mday, timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
* return sdt;
}- Hide quoted text -

- Show quoted text -
Here it is again, (Hopefully with better formatting)

System::DateTim e time_tToSystemD ateTime(time_t tt)
{
tm* timeptr = gmtime(&tt);
DateTime sdt(timeptr->tm_year + 1900,
timeptr->tm_mon + 1,
timeptr->tm_mday,
timeptr->tm_hour,
timeptr->tm_min,
timeptr->tm_sec);
return sdt;
}
Sep 23 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3951
by: Abdolhosein Vakilzadeh Ebrahimi | last post by:
Is there any way to construct a System.DateTime which doesn't check year, month and day to be in correct range== no validation? Thanks A.V.Ebrahimi
10
4481
by: Philip Wagenaar | last post by:
I have some code to convert a date to the unixdatetime representation (number of seconds since 1970). Only problem is that it only counts from the whole day, it ignores the times part. So convert 1/1/1970 and 1/1/1970 8:00:00 AM both return 0 but the last should return 28800. My code: Try Dim dte As DateTime dte = DateTime.Parse(CmdArgs(1)) Console.WriteLine(DateDiff(DateInterval.Second,
2
4798
by: ziggislaw | last post by:
hello how can I convert DateTime from "25.12.2005" to "2005-12-25 00:00:00.000" ? Now I have DateTime as string (I get it from <asp:label>). Thanks
14
7976
by: Me | last post by:
Hi all I am getting a really bizzare error on when I convert a string into a datetime: The code is : DateTime dt1 = Convert.ToDateTime("10 Sep 2005"); Console.WriteLine(dt1.Year);
4
35901
by: tshad | last post by:
Is there any difference between convert.ToDateTime and System.DateTime.Parse? I am using them both and they seem the same. Is one better to use than another? Thanks, Tom
1
4611
by: John | last post by:
I have a drop down that is showing dates, I need to pass the selected date to my proc, so I pass it like this; getCarSales(Convert.ToDateTime(carTimeFrame.selectedItem.value).ToShortDateString()); but when i compile I'm getting the error" 'cannot convert from 'string' to 'system.datetime' even if i hard code a date i'm getting this error. Now the getCarSales method as the date as
7
16729
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be returned from the source. My first attempt was as follows; (please ignore that error handling is not present in this example) public T GetValue<T(string objName) { T results;
1
2050
by: jimmybaba | last post by:
hi all i am newly graduate and started my first job.......i am geting problem to convert datetime into date only , i am trying to get values from sqlserver table with comparison of date. i am using c# what i am doing is: switch (completed) { case 0 : if(date<DateTime.Today) e.Cell.Text += "<tr><td style=\"font-size:8px;color:red;line-height:12px;vertical-align:center;\">"; ...
0
2827
by: maolimix | last post by:
Hi to all, I have a trouble with datetime...now I explain.. I must to store to a C# variable the values from a "Datetime column" of Sql Server 2005. I tried 3 methods ...in the first two I never was able to get the Millisecond from datacolumn. I explain the methods... 1) I created a Datatable that contain the column... then I fill a datarow with the current value. The system automatically converts the Sqldatetime in System.Datetime but...
0
9728
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10648
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10135
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.