简体   繁体   中英

Datetime.Now.Millisecond not showing full time format

While creating a log I am using Datetime.Now.Millisecond . But I am getting only millisecond. I am not getting the full time like 11/09/2015 10:59:48:936 but getting only 936 .

Where am I going wrong?

Because Millisecond property returns int it's millisecond part.

The milliseconds component, expressed as a value between 0 and 999 .

If you wanna get full time format as you want, you can generate it's string representation as;

DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss:fff", CultureInfo.InvariantCulture);

您应该使用DateTime.Now ,然后使用适当的格式字符串调用ToString以所需的方式获取输出

var result = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss:fff", CultureInfo.InvarianCutlure);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM