473,402 Members | 2,064 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,402 software developers and data experts.

Milliseconds From 1970!

I have a value that represents the time in milliseconds passed since
1970 00:00:00 GMT that I need to convert into a readable date e.g.

1092364211773 = 13/08/2004 03:30:00 GMT

Is this easily done or do I need to write my own function for this???
If that's the case, does anyone have some code to do this???

Thanks in advance

Steve
Jul 21 '05 #1
6 2060
Steve,
Have you tried the DateTime.AddMilliseconds method?

Something like:

Dim base As New DateTime(1970, 1, 1)
Dim readableDate As DateTime = base.AddMilliseconds(1092364211773)
Debug.WriteLine(readableDate, "Readable date")

Hope this helps
Jay

"Steve" <go****@valleyboy.net> wrote in message
news:7a**************************@posting.google.c om...
I have a value that represents the time in milliseconds passed since
1970 00:00:00 GMT that I need to convert into a readable date e.g.

1092364211773 = 13/08/2004 03:30:00 GMT

Is this easily done or do I need to write my own function for this???
If that's the case, does anyone have some code to do this???

Thanks in advance

Steve

Jul 21 '05 #2
Steve <go****@valleyboy.net> wrote:
I have a value that represents the time in milliseconds passed since
1970 00:00:00 GMT that I need to convert into a readable date e.g.

1092364211773 = 13/08/2004 03:30:00 GMT

Is this easily done or do I need to write my own function for this???
If that's the case, does anyone have some code to do this???


It's easy to create a DateTime for Jan 1st 1970, and a TimeSpan for
however many milliseconds you've got - then just add one to the other.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3
This is perfect, thank you so much...

Steve
-----Original Message-----
Steve,
Have you tried the DateTime.AddMilliseconds method?

Something like:

Dim base As New DateTime(1970, 1, 1)
Dim readableDate As DateTime = base.AddMilliseconds(1092364211773) Debug.WriteLine(readableDate, "Readable date")

Hope this helps
Jay

"Steve" <go****@valleyboy.net> wrote in message
news:7a**************************@posting.google. com...
I have a value that represents the time in milliseconds passed since 1970 00:00:00 GMT that I need to convert into a readable date e.g.
1092364211773 = 13/08/2004 03:30:00 GMT

Is this easily done or do I need to write my own function for this??? If that's the case, does anyone have some code to do this???
Thanks in advance

Steve

.

Jul 21 '05 #4
Steve,
If you go the TimeSpan route as Jon suggests. You can use
TimeSpan.FromMilliseconds to get a TimeSpan with milliseconds in it.

Dim base As New DateTime(1970, 1, 1)
Dim ts As TimeSpan = TimeSpan.FromMilliseconds(1092364211773)
Dim readableDate As DateTime = base.Add(ts)

Debug.WriteLine(readableDate, "Readable date")

I'm mentioning this as I "always" forget about the TimeSpan.From* methods...
*shrug*

Hope this helps
Jay

"Steve" <go****@valleyboy.net> wrote in message
news:5c****************************@phx.gbl...
This is perfect, thank you so much...

Steve
-----Original Message-----
Steve,
Have you tried the DateTime.AddMilliseconds method?

Something like:

Dim base As New DateTime(1970, 1, 1)
Dim readableDate As DateTime =

base.AddMilliseconds(1092364211773)
Debug.WriteLine(readableDate, "Readable date")

Hope this helps
Jay

"Steve" <go****@valleyboy.net> wrote in message
news:7a**************************@posting.google. com...
I have a value that represents the time in milliseconds passed since 1970 00:00:00 GMT that I need to convert into a readable date e.g.
1092364211773 = 13/08/2004 03:30:00 GMT

Is this easily done or do I need to write my own function for this??? If that's the case, does anyone have some code to do this???
Thanks in advance

Steve

.

Jul 21 '05 #5
You can set up a DateTime Structure for the date in 1970 and then use a
TimeSpan object with the requisite number of milliseconds and add to the
first DateTime to get another DateTime.

Dim dt as DateTime = Convert.ToDateTime("1/1/1970")

'Check this next line to make sure it is in the millisecond value
Dim ts As New TimeSpan(0,0,0,0,1092364211773)

Dim dt as DateTime = dt + ts

Something like that. Check the documentation if this blows chunks, but the
theory is sound.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"Steve" <go****@valleyboy.net> wrote in message
news:7a**************************@posting.google.c om...
I have a value that represents the time in milliseconds passed since
1970 00:00:00 GMT that I need to convert into a readable date e.g.

1092364211773 = 13/08/2004 03:30:00 GMT

Is this easily done or do I need to write my own function for this???
If that's the case, does anyone have some code to do this???

Thanks in advance

Steve

Jul 21 '05 #6
George,

In my opinion it is better to use as Jay showed
Dim base As New DateTime(1970, 1, 1)

That is independent from the culture settings.
(Assuming the time Steve is from the US however when others read this).

Cor
Jul 21 '05 #7

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

Similar topics

10
by: yaron | last post by:
Hi, I do i get the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC. like in java System.currentTimeMillis() ? Thanks.
6
by: Steve | last post by:
I have a value that represents the time in milliseconds passed since 1970 00:00:00 GMT that I need to convert into a readable date e.g. 1092364211773 = 13/08/2004 03:30:00 GMT Is this easily...
6
by: Steve | last post by:
I have a value that represents the time in milliseconds passed since 1970 00:00:00 GMT that I need to convert into a readable date e.g. 1092364211773 = 13/08/2004 03:30:00 GMT Is this easily...
2
by: vinodtr | last post by:
Hi all, I have a date which is represented by the number of milliseconds since January 01, 1970. I need to change this back to DATE format. Is there any built in function in DB2 to do the needed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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.