473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Conversion of hex value in milliseconds to datetime in c#2005

366 256MB
Hi friends

I am doing a project related embeded systems ,where my application reads data that generated by the device that connected to my application ,

the protocol that used for developing the firm ware of the device is DNP3

the date,month,year,hh,min,sec that generated by the device is in hexadecimal format

ex:EC5461887011 (the value generated by device in milli seconds from 1970 )

now my application should convert the above format to the datetime format in c#

can any one there for any idea or any existing function related to this


Regards

Msreddy
Nov 7 '07 #1
3 5585
Plater
7,872 Expert 4TB
Do you get a series of bytes (like a byte[]) or do you get a text string of "ECCEE4554" ?
Nov 8 '07 #2
balabaster
797 Expert 512MB
Do you get a series of bytes (like a byte[]) or do you get a text string of "ECCEE4554" ?
Now - "since 1970" is a fairly broad term...so you need to figure out the exact time to run from...so assuming we can figure this out:

Convert the hex to decimal...or not (if not, just add the hex notification so that the compiler knows how to convert it).

What about this? I'm assuming by "1970" you meant since 1/1/1970 12:00:00 AM otherwise just change the start date accordingly. Use the &H (VB) or 0x (C#) flag to notify the compiler that this value is hexadecimal. Obviously you would replace the literal that I used in my demo with a variable containing the literal value.
VB
Expand|Select|Wrap|Line Numbers
  1. Dim StartDate As DateTime = Convert.ToDateTime("1/1/1970 12:00:00 AM")
  2. Dim OutputDate As DateTime = StartDate.AddMilliseconds(&HECCEE4554)
C#
Expand|Select|Wrap|Line Numbers
  1. System.DateTime StartDate = Convert.ToDateTime("1/1/1970 12:00:00 AM");
  2. DateTime OutputDate = StartDate.AddMilliseconds(&HECCEE4554);
Hmm...just tested that with the original Hex string (&hEC5461887011) and it crashes because the number is too large...are we sure this isn't a byte array? Or in some other measure than milliseconds? If I add ticks, but I don't suppose that is correct...the resulting date doesn't seem high enough.
Nov 9 '07 #3
Plater
7,872 Expert 4TB
I am pretty sure that's just a made up hex number, as it's only 6bytes (whoever heard of a 24bit integer...)
Nov 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: daniel li | last post by:
I am working with some java/.net conversion project and I need to convert the following method into C#. private java.sql.Date convertDate( Calendar calendar ) { // calendar .getTime() returns a...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
11
by: Tim | last post by:
Hi, I am trying to do something simple. Convert a string date to datetime but it is not working and is giving me a baffling error! System.Convert.ToDateTime("Jan 30, 2006")...
7
by: Dick | last post by:
I have a long list of events. I know where each event took place (globally) and when (using the event’s local time). I want to do some comparisons between these date/times. I thought I would...
3
by: Mark | last post by:
I'd like to compare two datetime values in milliseconds. The datetime.compare method appears to show only seconds. Milliseconds of a datetime are available as a property of each datetime, but I...
6
by: Manikandan | last post by:
Hi, I need to insert the datetime with milliseconds value into a datarow. My code as below DataTable testDataTable=new DataTable(); testDataTable.Columns.Add("updatedDateTime",...
16
by: Nathan Sokalski | last post by:
I have a control uses the date and time, including milliseconds. I want to be able to enter this information as an attribute in the *.aspx page. Because all attributes are entered as strings in the...
5
by: Ivan Velev | last post by:
Hello, Minimal example below - it gives me different output if I comment / uncomment the extra time.mktime call - note that this call is not related in any way to main logic flow. When...
8
by: Jesper Lund Stocholm | last post by:
I am currently working on converting an old .Net 1.1-application to .Net 3.5. Due to the lack of nullable datatypes in those days, a "decimal wrapper" was created that had various methods to parse...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.