Windows用户登录时间的语法 [英] Syntax of login time of windows user
问题描述
大家好,
我想为Windows开发一个小型应用程序.在此,我想要当前用户的登录时间.通过代码的帮助,我也可以得到它,但是问题是我无法理解语法.因此,可以请我告诉我如何获取"DD/MM/YYYY HH:MM:SS AM/PM"格式的语法..
上面的语法与系统当前时间通过方法"DateTime.Now.ToString()"得到的语法相同.
语言-> C#
hello guys,
i want to develop a small application for windows. In this I want login time of the current user. By the help of a code I am able to get that also but the problem is that I am not able to understand the syntax. So can some plz tell me how to get the syntax in format of "DD/MM/YYYY HH:MM:SS AM/PM" ..
The above syntax is same as which i got by the method "DateTime.Now.ToString()" for current time of the system..
language --> C#
推荐答案
尝试:
DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt");
从在线文档 [
From the online documentation [^]on Date and Time formatting:
tt: Displays the A.M./P.M. designator for the specified DateTime.
当您没有告诉我们要转换为"DD/MM/YYYY HH:MM"的内容时,很难告知您:SS AM/PM"格式.
如果登录时间来自WMI,则它将是Distributed Management Task Force(DMTF)格式的字符串.在这种情况下,请使用System.Management.ManagementDateTimeConverter
类.
艾伦.
It''s difficult to advise when you haven''t told us what it is you are trying to convert to "DD/MM/YYYY HH:MM:SS AM/PM" format.
If the login time came from WMI then it will be a string in Distributed Management Task Force (DMTF) format. In which case use theSystem.Management.ManagementDateTimeConverter
class.
Alan.
此代码应该有效:
This code should work:
DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt");
但是,默认的DateTime.Now.ToString()格式可以通过本地化设置进行调整.例如,如果将当前线程的语言环境更改为"en-au",则将获得带有AM/PM的上述格式.每当您将其提供给SQL插入/更新
However, the default DateTime.Now.ToString() format could be adjusted through your localization settings. If you change the locale of the current thread to "en-au" for example, you will get the above format with the AM/PM. Be careful with these formatting whenever you give it to an SQL insert/update
这篇关于Windows用户登录时间的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!