tags:

views:

19

answers:

2

I am trying to save image captured from web cam with current time.Like

06.06.2010 22:29:52.jpg

But compiler does not allow time format 22:20:30 . I searched but I could not find how to write time like 22.29.59 or how can solve this problem ?

String photoTime = DateTime.Now.ToString();
String SuspiciousPath = Path.Combine(PhotoPath+"//suspicious",photoTime+".jpg");
FirstPersonTestImage.Save(SuspiciousPath);
+2  A: 

You can use DateTime.ToString("MM.dd.yyyy HH.mm.ss");

See full documentation in MSDN.

I recommend DateTime.ToString("yyyy_MM_dd.HH_mm_ss"); so you can sort by filename and it sorts by time.

brickner
A: 

You need to use a custom format string, like this:

String photoTime = DateTime.Now.ToString("MM.dd.yyyy HH.mm.ss");

However, I recommend that you use a sortable format, like this:

String photoTime = DateTime.Now.ToString("yyyy-MM-dd, HH.mm.ss");

These strings will sort by timestamp.

SLaks