473,396 Members | 1,706 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,396 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 5586
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.