473,399 Members | 3,888 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,399 software developers and data experts.

How do I write a timestamp that is more accurate than milliseconds?

Hi,
I have a program that is listening for messages on a port and writes each message to a separate file. I'm currently using the DateTime Now to write a time stamp into the file name so that each message has a unique name (i.e. doesn't get overwritten by the next)

However some messages are getting overwritten by the next message since the time did not yet have a chance to advance to change the file name time stamp. (machine is very fast and messages are coming in quickly)

For each message the program resets and so I cannot use a counter inside the program. and I cannot change this aspect of the program.

Is there another way other than DateTime, to generate a unique number for each file that does not rely on a counter inside the program itself?

Thanks for any help
Sep 18 '10 #1

✓ answered by Christian Binder

If all your files are in the same folder, you can check all the filenames of the files in this folder and create a filename, which wasn't used before.

Or you use DateTime.Now.Ticks as suggested.

Or you can use Guid.NewGuid() which creates a globally unique identifier who can be used for creating a filename.
(But this would cause unsorted filenames.

You could also use a file where you are storing a counter and take this for the filename.

4 3493
Aimee Bailey
197 Expert 100+
DateTime has a more accurate measurement called .Ticks. This may not be the perfect answer, but it'll give you a more accurate timestamp.

Aimee.
Sep 21 '10 #2
GaryTexmo
1,501 Expert 1GB
If it helps, there are 10 000 ticks in a millisecond.

http://msdn.microsoft.com/en-us/libr...ime.ticks.aspx
Sep 22 '10 #3
Christian Binder
218 Expert 100+
If all your files are in the same folder, you can check all the filenames of the files in this folder and create a filename, which wasn't used before.

Or you use DateTime.Now.Ticks as suggested.

Or you can use Guid.NewGuid() which creates a globally unique identifier who can be used for creating a filename.
(But this would cause unsorted filenames.

You could also use a file where you are storing a counter and take this for the filename.
Sep 22 '10 #4
Hey everyone, thanks for the suggestions. In the end I stuck with the milliseconds in the time stamp, but just added the NewGuid value as Christian suggested since all I cared about was preventing the files from getting overwritten, the file name itself wasn't too much of an issue.
Sep 24 '10 #5

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

Similar topics

15
by: mjs7231 | last post by:
I am trying to record how long an operation takes, but can't seem to find a function that will allow me to record the timestamp in milliseconds, maybe I am looking in the wrong place?
1
by: ts | last post by:
In 10g why can I not get a 6 digit millisecond timestamp. Here is my Sql. Select Current_Timestamp(6) from dual; The milliseconds always looks like .931000. -thanks
1
by: Roberto Nenni | last post by:
hi all and sorry for my english I write into a SqlServer2000 database via jdbc using a PreparedStatement (pstmt) and one of fields is a TimeStamp, my code is: qwdum=System.currentTimeMillis();...
2
by: Alex | last post by:
Hi all, Got a small problem here. I have a number of web caches here that generate loads and loads of log files and instead of keeping them for analysis I want to write them to a db/2...
1
by: Antony Paul | last post by:
Hi all What is the last value in a column of data type timestamp without time zone. A sample data is 2004-06-22 18:07:00.486027. What does 486027 mean Milliseconds or seconds since midnight or...
5
by: Brett Romero | last post by:
I have this in an app.config file: <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.diagnostics> <trace autoflush="true" indentsize="2"> <listeners> <add name="myListener"...
1
by: Benny Schudel | last post by:
hello I've tried to convert some milliseconds to a time format. $ms = 100000 // 1min 40sec echo strftime('%H:%M:%S', $ms/1000); i expect the result is: "00:01:40" but the result ist:...
2
by: pankajit09 | last post by:
Hi <script type="text/javascript"> var d = new Date(); var timeStamp =...
2
by: bruceturek | last post by:
I'm having an issue that I'm sure there is a simple fix for! I'm creating a java script that will dynamically create a URL. In the process I need to include a URL parameter '&timestamp=' followed...
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: 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
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
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.