开发者

how to afix this hhmmss problem

I was doing window services where I'm generating txt files in target path based on some details from a database but I have a problem the service is running too fast!

I was getting same file name in the place of sec variation required so that i can avoid duplicates over there.

code :

using (transactionscope scope = new transactionscope ) 
{
  string nowtime = datetime.now.today.to开发者_如何学Pythonstring(HHMMss) // it was working fine 
}

file should be generates by specific file naming convention !! ex:hhmmss >>> no millisecond can any one give me exclusive ideas how to face this part?


You can add milliseconds to the filename:

string nowtime = datetime.Now.Today.ToString("HHmmssfff");

See Custom Date and Time Format Strings.

A few notes about the code you posted:

  1. MM is for months, not minutes. You should use lower case mm.
  2. The parameter that ToString takes is a string.
  3. Your code wouldn't compile as it is not correctly cased. Please use code that can be directly used in the future.

Update:

Seeing as you have to use this format, the only other choice is to "slow down" the service.

Adding a:

Thread.Wait(1000);

In the right place (end of loop?) could do the trick.

Alternatively, you can change your code to append to a file if you are still within the same second.


If you are saying that you are creating multiple files with the same name (multiple files in the same second), then I would take the time out to the milliseconds. You can do this with:

DateTime.Today.ToString("HHmmssfff");

The fff denotes the three places to the right of the decimal (thousandths of a second).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜