How to maintain TimeStamp consistency across Time Zones?
Author |
Message |
Joseph Geret #1 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
I am working on a system which will involve data exchange and coordination across time zones. Bits of data are timestamped to ensure that the most recent data is used, in the event of a 'collision'. I have worked out the following 'pseudo-algorithm' for maintaining the integrity of the timestamps but I'd appreciate if you could point me in the right direction as far as the implementation is concerned. (All platforms are .NET.) The system consists of a central server, plus multiple workstation nodes. For the purposes of the basic methodology, all hardware platforms can be considered as a 'Node' * When data is stored / manipulated on a Node, local time (and local formatting) is used. * When data is TRASMITTED from a Node the accompanying timestamp is converted to Universal Time. * When data is RECEIVED at a Node, the accompanying timestamp is converted to Local Time. (As mentioned above, intra-Node time comparisons and formatting is performed using local time and local formatting.) Basically, I need to know how to convert from local time to universal time and vice versa. Any additional pointers which you can provide on the subject of multi-zone timestamping will be very much appreciated as well. Thanks for your help. - Joe Geretz -
|
Mon, 04 Apr 2005 07:48:00 GMT |
|
 |
Joseph Geret #2 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
Hi Chris, Thanks for the pointers. The code samples you present will work when I need to use the current date/time since the Now function returns a DateTime value. However, there are other occasions, when working with files, that the file system returns me a TimeStamp in the following format: 10/5/2002 11:20:10 PM How can I convert this into DateTime format? Thanks, - Joe Geretz -
Quote: > > * When data is stored / manipulated on a Node, local time (and local > > formatting) is used. > DateTime storeTime = DateTime.Now; > > * When data is TRASMITTED from a Node the accompanying timestamp is > > converted to Universal Time. > DateTime universalTime = storeTime.ToUniversalTime(); > > * When data is RECEIVED at a Node, the accompanying timestamp is > > converted to Local Time. (As mentioned above, intra-Node time > > comparisons and formatting is performed using local time and local > > formatting.) > DateTime localTime = universalTime.ToLocalTime(); > DateTime itself doesn't contain any cultural Formatting, so that > will be something determined by the DateTimeFormatInfo Class and > CultureInfo Class when you want to do conversion of DateTime to string. > Chris R
> > I am working on a system which will involve data exchange and > coordination > > across time zones. Bits of data are timestamped to ensure that the > most > > recent data is used, in the event of a 'collision'. I have worked out > the > > following 'pseudo-algorithm' for maintaining the integrity of the > timestamps > > but I'd appreciate if you could point me in the right direction as far > as > > the implementation is concerned. (All platforms are .NET.) > > The system consists of a central server, plus multiple workstation > nodes. > > For the purposes of the basic methodology, all hardware platforms can > be > > considered as a 'Node' > > * When data is stored / manipulated on a Node, local time (and local > > formatting) is used. > > * When data is TRASMITTED from a Node the accompanying timestamp is > > converted to Universal Time. > > * When data is RECEIVED at a Node, the accompanying timestamp is > converted > > to Local Time. (As mentioned above, intra-Node time comparisons and > > formatting is performed using local time and local formatting.) > > Basically, I need to know how to convert from local time to universal > time > > and vice versa. Any additional pointers which you can provide on the > subject > > of multi-zone timestamping will be very much appreciated as well. > > Thanks for your help. > > - Joe Geretz -
|
Mon, 04 Apr 2005 11:09:35 GMT |
|
 |
J. Dilfe #3 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
Not sure if I understand your algorithm fully, but just want to point out that if clocks on nodes aren't set correctly you may have issues. This acually happened at somewhere I worked. The time on one of the servers wasn't set correctly, it was off by an like hour (its local time). This caused fault detection of collisions. Resolution was to config all computers to sync clock with central source when rebooted.
Quote: > Hi Chris, > Thanks for the pointers. The code samples you present will work when I need > to use the current date/time since the Now function returns a DateTime > value. However, there are other occasions, when working with files, that the > file system returns me a TimeStamp in the following format: > 10/5/2002 11:20:10 PM > How can I convert this into DateTime format? > Thanks, > - Joe Geretz -
> > > * When data is stored / manipulated on a Node, local time (and local > > > formatting) is used. > > DateTime storeTime = DateTime.Now; > > > * When data is TRASMITTED from a Node the accompanying timestamp is > > > converted to Universal Time. > > DateTime universalTime = storeTime.ToUniversalTime(); > > > * When data is RECEIVED at a Node, the accompanying timestamp is > > > converted to Local Time. (As mentioned above, intra-Node time > > > comparisons and formatting is performed using local time and local > > > formatting.) > > DateTime localTime = universalTime.ToLocalTime(); > > DateTime itself doesn't contain any cultural Formatting, so that > > will be something determined by the DateTimeFormatInfo Class and > > CultureInfo Class when you want to do conversion of DateTime to string. > > Chris R
> > > I am working on a system which will involve data exchange and > > coordination > > > across time zones. Bits of data are timestamped to ensure that the > > most > > > recent data is used, in the event of a 'collision'. I have worked out > > the > > > following 'pseudo-algorithm' for maintaining the integrity of the > > timestamps > > > but I'd appreciate if you could point me in the right direction as far > > as > > > the implementation is concerned. (All platforms are .NET.) > > > The system consists of a central server, plus multiple workstation > > nodes. > > > For the purposes of the basic methodology, all hardware platforms can > > be > > > considered as a 'Node' > > > * When data is stored / manipulated on a Node, local time (and local > > > formatting) is used. > > > * When data is TRASMITTED from a Node the accompanying timestamp is > > > converted to Universal Time. > > > * When data is RECEIVED at a Node, the accompanying timestamp is > > converted > > > to Local Time. (As mentioned above, intra-Node time comparisons and > > > formatting is performed using local time and local formatting.) > > > Basically, I need to know how to convert from local time to universal > > time > > > and vice versa. Any additional pointers which you can provide on the > > subject > > > of multi-zone timestamping will be very much appreciated as well. > > > Thanks for your help. > > > - Joe Geretz -
|
Mon, 04 Apr 2005 12:12:45 GMT |
|
 |
Joseph Geret #4 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
Oops, Cancel that. The file date is a System.DateTime. Perfect! However, I need to translate this into a string format which can be easily 'reassembled' into a DateTime object at the target node. I can't pass this as a DateString (e.g. .ToLongDateString) since this format would be dependent on the locale of the particular Node (e.g. mm/dd/yy vs. dd/mm/yy) and the target Node would have no way of knowing this. Also, it needs to be presented at the target Node in such a manner so that it can be used easily to instantiate a DateTime object. Here's the method I developed to transform the file date into Universal time and then into my own 'Portable Time String', which looks like 2002|10|8|0|21|42|0 The components of this portable Time String are year, month day, hour, minute, second, millisecond. These are exactly what's needed to construct a DataTime object with the greatest degree of precision. private string zGetDateTime(System.DateTime DT) { DateTime UT; // Universal Time string PTS; // Portable Time String UT = DT.ToUniversalTime(); PTS = UT.Year.ToString() + "|" + UT.Month.ToString() + "|" + UT.Day.ToString() + "|" + UT.Hour.ToString() + "|" + UT.Minute.ToString() + "|" + UT.Second.ToString() + "|" + UT.Millisecond.ToString(); return PTS; Quote: }
Is this necessary, or have I missed something basic? Thanks, - Joe Geretz -
Quote: > Hi Chris, > Thanks for the pointers. The code samples you present will work when I need > to use the current date/time since the Now function returns a DateTime > value. However, there are other occasions, when working with files, that the > file system returns me a TimeStamp in the following format: > 10/5/2002 11:20:10 PM > How can I convert this into DateTime format? > Thanks, > - Joe Geretz -
> > > * When data is stored / manipulated on a Node, local time (and local > > > formatting) is used. > > DateTime storeTime = DateTime.Now; > > > * When data is TRASMITTED from a Node the accompanying timestamp is > > > converted to Universal Time. > > DateTime universalTime = storeTime.ToUniversalTime(); > > > * When data is RECEIVED at a Node, the accompanying timestamp is > > > converted to Local Time. (As mentioned above, intra-Node time > > > comparisons and formatting is performed using local time and local > > > formatting.) > > DateTime localTime = universalTime.ToLocalTime(); > > DateTime itself doesn't contain any cultural Formatting, so that > > will be something determined by the DateTimeFormatInfo Class and > > CultureInfo Class when you want to do conversion of DateTime to string. > > Chris R
> > > I am working on a system which will involve data exchange and > > coordination > > > across time zones. Bits of data are timestamped to ensure that the > > most > > > recent data is used, in the event of a 'collision'. I have worked out > > the > > > following 'pseudo-algorithm' for maintaining the integrity of the > > timestamps > > > but I'd appreciate if you could point me in the right direction as far > > as > > > the implementation is concerned. (All platforms are .NET.) > > > The system consists of a central server, plus multiple workstation > > nodes. > > > For the purposes of the basic methodology, all hardware platforms can > > be > > > considered as a 'Node' > > > * When data is stored / manipulated on a Node, local time (and local > > > formatting) is used. > > > * When data is TRASMITTED from a Node the accompanying timestamp is > > > converted to Universal Time. > > > * When data is RECEIVED at a Node, the accompanying timestamp is > > converted > > > to Local Time. (As mentioned above, intra-Node time comparisons and > > > formatting is performed using local time and local formatting.) > > > Basically, I need to know how to convert from local time to universal > > time > > > and vice versa. Any additional pointers which you can provide on the > > subject > > > of multi-zone timestamping will be very much appreciated as well. > > > Thanks for your help. > > > - Joe Geretz -
|
Mon, 04 Apr 2005 12:23:49 GMT |
|
 |
Joseph Geret #5 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
Hi J., Yep, I've been at this for 15 years now and no one has managed to solve the problem of GIGO :-) However, the problem of an incorrectly set Node is localized to the Node itself. In other words if I have my system clock set to 1/1/2009 I won't be seeing updates on my Node. But that's my own fault. In a more reasonable situation, if my clock is 1 minute ahead of the server, I won't see new data until one minute after my latest change. However, in this case my data is only 1 minute out of date at any given time. Not a big deal in this context. On the other hand, when I send data over to the server, it gets timestamped with the Universal Time according to the Server's time clock. Of course, an incorrectly clocked server could wreak havoc! this really shouldn't happen though since the server is periodically synced with a time server. And workstations on the IntraNet are synced with the server. But this is a good point you raise and I'll make sure that the importance of an accurately clocked workstation (and server!) is emphasized in the documentation. (Hmm, when the user logs in, or even on a transactional basis, I could send over the Universal Time calculated on the server and compare it with the locally calculated Universal time to see if they match (give or take a second or two). If they're off I could warn the user, or adjust the local clock. I'm not sure that this should be within the province of my system though. Food for thought...) Thanks for your suggestion, - Joe Geretz -
Quote: > Not sure if I understand your algorithm fully, but just want to point out > that if clocks on nodes aren't set correctly you may have issues. This > acually happened at somewhere I worked. The time on one of the servers > wasn't set correctly, it was off by an like hour (its local time). This > caused fault detection of collisions. Resolution was to config all > computers to sync clock with central source when rebooted.
> > Hi Chris, > > Thanks for the pointers. The code samples you present will work when I > need > > to use the current date/time since the Now function returns a DateTime > > value. However, there are other occasions, when working with files, that > the > > file system returns me a TimeStamp in the following format: > > 10/5/2002 11:20:10 PM > > How can I convert this into DateTime format? > > Thanks, > > - Joe Geretz -
> > > > * When data is stored / manipulated on a Node, local time (and local > > > > formatting) is used. > > > DateTime storeTime = DateTime.Now; > > > > * When data is TRASMITTED from a Node the accompanying timestamp is > > > > converted to Universal Time. > > > DateTime universalTime = storeTime.ToUniversalTime(); > > > > * When data is RECEIVED at a Node, the accompanying timestamp is > > > > converted to Local Time. (As mentioned above, intra-Node time > > > > comparisons and formatting is performed using local time and local > > > > formatting.) > > > DateTime localTime = universalTime.ToLocalTime(); > > > DateTime itself doesn't contain any cultural Formatting, so that > > > will be something determined by the DateTimeFormatInfo Class and > > > CultureInfo Class when you want to do conversion of DateTime to string. > > > Chris R
> > > > I am working on a system which will involve data exchange and > > > coordination > > > > across time zones. Bits of data are timestamped to ensure that the > > > most > > > > recent data is used, in the event of a 'collision'. I have worked out > > > the > > > > following 'pseudo-algorithm' for maintaining the integrity of the > > > timestamps > > > > but I'd appreciate if you could point me in the right direction as far > > > as > > > > the implementation is concerned. (All platforms are .NET.) > > > > The system consists of a central server, plus multiple workstation > > > nodes. > > > > For the purposes of the basic methodology, all hardware platforms can > > > be > > > > considered as a 'Node' > > > > * When data is stored / manipulated on a Node, local time (and local > > > > formatting) is used. > > > > * When data is TRASMITTED from a Node the accompanying timestamp is > > > > converted to Universal Time. > > > > * When data is RECEIVED at a Node, the accompanying timestamp is > > > converted > > > > to Local Time. (As mentioned above, intra-Node time comparisons and > > > > formatting is performed using local time and local formatting.) > > > > Basically, I need to know how to convert from local time to universal > > > time > > > > and vice versa. Any additional pointers which you can provide on the > > > subject > > > > of multi-zone timestamping will be very much appreciated as well. > > > > Thanks for your help. > > > > - Joe Geretz -
|
Mon, 04 Apr 2005 13:18:06 GMT |
|
 |
Pierre Grebori #6 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
I don't know if this answer your question: Console.WriteLine("From UNC to Local time {0}", DateTime.Now.ToUniversalTime().ToLocalTime()); Console.WriteLine("From Local time to UNC {0}", DateTime.Now.ToLocalTime().ToUniversalTime()); Pierre -- --------------------------------------------------------------- Pierre Greborio
http://www.pierregreborio.it UGIDOTNET http://www.ugidotnet.org ---------------------------------------------------------------
Quote: > I am working on a system which will involve data exchange and coordination > across time zones. Bits of data are timestamped to ensure that the most > recent data is used, in the event of a 'collision'. I have worked out the > following 'pseudo-algorithm' for maintaining the integrity of the timestamps > but I'd appreciate if you could point me in the right direction as far as > the implementation is concerned. (All platforms are .NET.) > The system consists of a central server, plus multiple workstation nodes. > For the purposes of the basic methodology, all hardware platforms can be > considered as a 'Node' > * When data is stored / manipulated on a Node, local time (and local > formatting) is used. > * When data is TRASMITTED from a Node the accompanying timestamp is > converted to Universal Time. > * When data is RECEIVED at a Node, the accompanying timestamp is converted > to Local Time. (As mentioned above, intra-Node time comparisons and > formatting is performed using local time and local formatting.) > Basically, I need to know how to convert from local time to universal time > and vice versa. Any additional pointers which you can provide on the subject > of multi-zone timestamping will be very much appreciated as well. > Thanks for your help. > - Joe Geretz -
|
Mon, 04 Apr 2005 13:20:47 GMT |
|
 |
Jon Skee #7 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
Quote:
> The components of this portable Time String are year, month day, hour, > minute, second, millisecond. These are exactly what's needed to construct a > DataTime object with the greatest degree of precision.
<snip> Quote: > Is this necessary, or have I missed something basic?
I'd personally just send over the DateTime's "ticks" property, which you can then use to construct the DateTime again at the other side (both in UTC, of course). --
http://www.pobox.com/~skeet/ If replying to the group, please do not mail me too
|
Mon, 04 Apr 2005 15:18:24 GMT |
|
 |
Thomas Tomiczek [MVP #8 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
Sort of - I go this way, too :-) But the string is human readable, if you care about this. -- Regards Thomas Tomiczek THONA Consulting Ltd. (Microsoft MVP C#/.NET) -- Still writing SQL and dealing with DataSets? Why dont you use our EntityBroker - the most advanced o/r and business object toolkit in town.
Quote:
> > The components of this portable Time String are year, month day, hour, > > minute, second, millisecond. These are exactly what's needed to construct a > > DataTime object with the greatest degree of precision. > <snip> > > Is this necessary, or have I missed something basic? > I'd personally just send over the DateTime's "ticks" property, which you > can then use to construct the DateTime again at the other side (both in > UTC, of course). > --
> http://www.pobox.com/~skeet/ > If replying to the group, please do not mail me too
|
Mon, 04 Apr 2005 15:28:25 GMT |
|
 |
Joseph Geret #9 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
Hi Chris, Thanks for pointing out the Parse method but I don't think I can use it, at least not for decoding dates passed between Nodes. Quote: > DateTime dt = DateTime.Parse( "10/5/2002 11:20:10 PM" );
Is that October 5, 2002 or May 10, 2002? It would depend on whether the originating Node was in Europe or in the U.S. - Joe Geretz - Quote:
> > Hi Chris, > > Thanks for the pointers. The code samples you present will work when I > need > > to use the current date/time since the Now function returns a DateTime > > value. However, there are other occasions, when working with files, > that the > > file system returns me a TimeStamp in the following format: > > 10/5/2002 11:20:10 PM > > How can I convert this into DateTime format? > > Thanks, > > - Joe Geretz -
> > > > * When data is stored / manipulated on a Node, local time (and > local > > > > formatting) is used. > > > DateTime storeTime = DateTime.Now; > > > > * When data is TRASMITTED from a Node the accompanying timestamp > is > > > > converted to Universal Time. > > > DateTime universalTime = storeTime.ToUniversalTime(); > > > > * When data is RECEIVED at a Node, the accompanying timestamp is > > > > converted to Local Time. (As mentioned above, intra-Node time > > > > comparisons and formatting is performed using local time and local > > > > formatting.) > > > DateTime localTime = universalTime.ToLocalTime(); > > > DateTime itself doesn't contain any cultural Formatting, so that > > > will be something determined by the DateTimeFormatInfo Class and > > > CultureInfo Class when you want to do conversion of DateTime to > string. > > > Chris R
> > > > I am working on a system which will involve data exchange and > > > coordination > > > > across time zones. Bits of data are timestamped to ensure that the > > > most > > > > recent data is used, in the event of a 'collision'. I have worked > out > > > the > > > > following 'pseudo-algorithm' for maintaining the integrity of the > > > timestamps > > > > but I'd appreciate if you could point me in the right direction as > far > > > as > > > > the implementation is concerned. (All platforms are .NET.) > > > > The system consists of a central server, plus multiple workstation > > > nodes. > > > > For the purposes of the basic methodology, all hardware platforms > can > > > be > > > > considered as a 'Node' > > > > * When data is stored / manipulated on a Node, local time (and > local > > > > formatting) is used. > > > > * When data is TRASMITTED from a Node the accompanying timestamp > is > > > > converted to Universal Time. > > > > * When data is RECEIVED at a Node, the accompanying timestamp is > > > converted > > > > to Local Time. (As mentioned above, intra-Node time comparisons > and > > > > formatting is performed using local time and local formatting.) > > > > Basically, I need to know how to convert from local time to > universal > > > time > > > > and vice versa. Any additional pointers which you can provide on > the > > > subject > > > > of multi-zone timestamping will be very much appreciated as well. > > > > Thanks for your help. > > > > - Joe Geretz -
|
Tue, 05 Apr 2005 00:30:09 GMT |
|
 |
Joseph Geret #10 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
Thanks Jon, Ticks is good. I will use it for the sake of efficiency and code reduction. (I mistakenly thought ticks was relative to 00:00.00 of the current date. I've got to find some way to cure these old DOS flashbacks...) :-) - Joe Geretz -
Quote:
> > The components of this portable Time String are year, month day, hour, > > minute, second, millisecond. These are exactly what's needed to construct a > > DataTime object with the greatest degree of precision. > <snip> > > Is this necessary, or have I missed something basic? > I'd personally just send over the DateTime's "ticks" property, which you > can then use to construct the DateTime again at the other side (both in > UTC, of course). > --
> http://www.pobox.com/~skeet/ > If replying to the group, please do not mail me too
|
Tue, 05 Apr 2005 00:26:26 GMT |
|
 |
Joseph Geret #11 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
Hi Pierre. That's for your help. Additionally, I use Ticks to transmit the time between nodes so that the representation of the time is not dependent on the locale settings of either the source or destination Node. - Joe Geretz -
Quote: > I don't know if this answer your question: > Console.WriteLine("From UNC to Local time {0}", > DateTime.Now.ToUniversalTime().ToLocalTime()); > Console.WriteLine("From Local time to UNC {0}", > DateTime.Now.ToLocalTime().ToUniversalTime()); > Pierre > -- > --------------------------------------------------------------- > Pierre Greborio
> http://www.pierregreborio.it > UGIDOTNET http://www.ugidotnet.org > ---------------------------------------------------------------
> > I am working on a system which will involve data exchange and coordination > > across time zones. Bits of data are timestamped to ensure that the most > > recent data is used, in the event of a 'collision'. I have worked out the > > following 'pseudo-algorithm' for maintaining the integrity of the > timestamps > > but I'd appreciate if you could point me in the right direction as far as > > the implementation is concerned. (All platforms are .NET.) > > The system consists of a central server, plus multiple workstation nodes. > > For the purposes of the basic methodology, all hardware platforms can be > > considered as a 'Node' > > * When data is stored / manipulated on a Node, local time (and local > > formatting) is used. > > * When data is TRASMITTED from a Node the accompanying timestamp is > > converted to Universal Time. > > * When data is RECEIVED at a Node, the accompanying timestamp is converted > > to Local Time. (As mentioned above, intra-Node time comparisons and > > formatting is performed using local time and local formatting.) > > Basically, I need to know how to convert from local time to universal time > > and vice versa. Any additional pointers which you can provide on the > subject > > of multi-zone timestamping will be very much appreciated as well. > > Thanks for your help. > > - Joe Geretz -
|
Tue, 05 Apr 2005 00:44:32 GMT |
|
 |
Joseph Geret #12 / 12
|
 How to maintain TimeStamp consistency across Time Zones?
Hi Chris, I think DateTime.Ticks, as others have suggested, is the best locale independent date/time format. Here's how I take a local date and 'transform' it for trasmission to a target node. private string zPortableTimeString(System.DateTime DT) { return DT.ToUniversalTime().Ticks.ToString(); Quote: }
Although it's a simple one-liner I've encapsulated it within a method in case I need to change the format of my Portable Time String in the future.) - Joe Geretz -
Quote: > This will work > From any time zone in any culture > To any time zone in any culture. > UIDT = Universal Invariant DateTime > *************************** > // Method to create a Universal & Invariant DateTime string > // from the Local Culture TimeStamp. > public string GetUIDTFromLocalTimeStamp( string timeStamp ) > { > // timeStamp --> Local DateTime > DateTime LT = DateTime.Parse( timeStamp ); > // Local DateTime --> Universal DateTime > DateTime UDT = LT.ToUniversalTime(); > // Universal & Invariant DateTime --> string > DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo; > return UDT.ToString("G", dtfi ); > } > *************************** > Send the UIDTString across the network. It will still be > in human readable format, but not localized. > *************************** > // Method to read a Universal Time-Invariant string > // and return the Local Culture TimeStamp.. > public string GetLocalTimeStampFromUIDT( sting strUIDT ) > { > // Universal & Invariant DateTime --> Universal DateTime > DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo; > DateTime UDT = DateTime.Parse( strUIDT, dtfi ); > // Universal DateTime --> Local DateTime > DateTime LT = UDT.ToLocalTime(); > // String Value (since timeStamp is a string) > return LT.ToString("G"); > } > *************************** > Of course, sending it as Ticks works pretty much the same way. You'd > just be sending a long instead of a string. > Chris R.
> > Oops, > > Cancel that. The file date is a System.DateTime. Perfect! > > However, I need to translate this into a string format which can be > easily > > 'reassembled' into a DateTime object at the target node. I can't pass > this > > as a DateString (e.g. .ToLongDateString) since this format would be > > dependent on the locale of the particular Node (e.g. mm/dd/yy vs. > dd/mm/yy) > > and the target Node would have no way of knowing this. Also, it needs > to be > > presented at the target Node in such a manner so that it can be used > easily > > to instantiate a DateTime object. Here's the method I developed to > transform > > the file date into Universal time and then into my own 'Portable Time > > String', which looks like > > 2002|10|8|0|21|42|0 > > The components of this portable Time String are year, month day, hour, > > minute, second, millisecond. These are exactly what's needed to > construct a > > DataTime object with the greatest degree of precision. > > private string zGetDateTime(System.DateTime DT) > > { > > DateTime UT; // Universal Time > > string PTS; // Portable Time String > > UT = DT.ToUniversalTime(); > > PTS = UT.Year.ToString() + "|" > > + UT.Month.ToString() + "|" > > + UT.Day.ToString() + "|" > > + UT.Hour.ToString() + "|" > > + UT.Minute.ToString() + "|" > > + UT.Second.ToString() + "|" > > + UT.Millisecond.ToString(); > > return PTS; > > } > > Is this necessary, or have I missed something basic? > > Thanks, > > - Joe Geretz -
> > > Hi Chris, > > > Thanks for the pointers. The code samples you present will work when > I > > need > > > to use the current date/time since the Now function returns a > DateTime > > > value. However, there are other occasions, when working with files, > that > > the > > > file system returns me a TimeStamp in the following format: > > > 10/5/2002 11:20:10 PM > > > How can I convert this into DateTime format? > > > Thanks, > > > - Joe Geretz -
> > > > > * When data is stored / manipulated on a Node, local time (and > local > > > > > formatting) is used. > > > > DateTime storeTime = DateTime.Now; > > > > > * When data is TRASMITTED from a Node the accompanying timestamp > is > > > > > converted to Universal Time. > > > > DateTime universalTime = storeTime.ToUniversalTime(); > > > > > * When data is RECEIVED at a Node, the accompanying timestamp is > > > > > converted to Local Time. (As mentioned above, intra-Node time > > > > > comparisons and formatting is performed using local time and > local > > > > > formatting.) > > > > DateTime localTime = universalTime.ToLocalTime(); > > > > DateTime itself doesn't contain any cultural Formatting, so > that > > > > will be something determined by the DateTimeFormatInfo Class and > > > > CultureInfo Class when you want to do conversion of DateTime to > string. > > > > Chris R
> > > > > I am working on a system which will involve data exchange and > > > > coordination > > > > > across time zones. Bits of data are timestamped to ensure that > the > > > > most > > > > > recent data is used, in the event of a 'collision'. I have > worked out > > > > the > > > > > following 'pseudo-algorithm' for maintaining the integrity of > the > > > > timestamps > > > > > but I'd appreciate if you could point me in the right direction > as far > > > > as > > > > > the implementation is concerned. (All platforms are .NET.) > > > > > The system consists of a central server, plus multiple > workstation > > > > nodes. > > > > > For the purposes of the basic methodology, all hardware > platforms can > > > > be > > > > > considered as a 'Node' > > > > > * When data is stored / manipulated on a Node, local time (and > local > > > > > formatting) is used. > > > > > * When data is TRASMITTED from a Node the accompanying timestamp > is > > > > > converted to Universal Time. > > > > > * When data is RECEIVED at a Node, the accompanying timestamp is > > > > converted > > > > > to Local Time. (As mentioned above, intra-Node time comparisons > and > > > > > formatting is performed using local time and local formatting.) > > > > > Basically, I need to know how to convert from local time to > universal > > > > time > > > > > and vice versa. Any additional pointers which you can provide on > the > > > > subject > > > > > of multi-zone timestamping will be very much appreciated as > well. > > > > > Thanks for your help. > > > > > - Joe Geretz -
|
Tue, 05 Apr 2005 00:54:09 GMT |
|
|
|