我不小心通过了0到DateTimeFormatInfo的GetMonthName方法:
DateTimeFormatInfo info = new DateTimeFormatInfo();
var monthName = info.GetMonthName(0);
Run Code Online (Sandbox Code Playgroud)
并得到一个System.ArgumentOutOfRangeException带有此错误消息:有效值介于1和13之间(包括1和13).
传入1到12返回"1月"到"12月",但传入13返回空字符串.
我可以看到为什么月数不是零索引,但是13月是什么?
我们的测试中 Intl.DateTimeFormat 有一个奇怪的行为(但在 Node 或 chrome 控制台中也是如此)。
这个功能:
Intl.DateTimeFormat('en-AU', { year: 'numeric', month: 'short', day: 'numeric' }).format(new Date());
Run Code Online (Sandbox Code Playgroud)
将返回month day, yearCI 或我的同事在 mac 和 Linux 机器上(英语语言设置)。
但它会返回day month year到我的机器上(mac,英语语言设置)。
以今天为例,即使我们依赖相同的区域设置,它也会Jan 13, 2021对某些人和其他人返回。13 Jan 2021并且它在机器上是一致的,结果与 jest run、节点控制台或浏览器控制台相同。
知道是什么原因造成的吗?
是否有DateTimeFormatInfo格式模式将一周中的某一天转换为两个字符?例如星期二变成涂,星期三变成我们.格式字符串需要符合DateTimeFormatInfo for日期格式.
加成:
也许我正在寻找扩展DateTimeFormatInfo到包含自定义格式的解决方案?
以下代码:
DateTimeFormatInfo datetimeinfo = new CultureInfo("en-GB", false).DateTimeFormat;
string[] months = datetimeinfo.MonthNames;
Run Code Online (Sandbox Code Playgroud)
返回13个成员,0表示1月,13表示空字符串.
为什么是这样?
这没什么大不了的,因为我可以删除最后一个成员,但我只是想知道它是否有意义.
我正在尝试插入数据库 - 有关事件的各种详细信息.asp.net文本框正在使用Calendar Extender(因此弹出一个小日历并使用正确格式化的日期填充文本框).Access数据库中的EventDate字段的类型为Date/Time.我需要将文本/字符串转换为日期/时间格式
到目前为止我试过这个:
VB:
Run Code Online (Sandbox Code Playgroud)Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("BookMeetConnString").ConnectionString) Dim SqlString As String = "Insert into Events(EventTitle,EventDescription,EventDate,EventCategory) Values (@f1,@f2,@f3,@f4)" Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn) Dim strDate As String = tb_eventdate.Text Dim dtfi As New System.Globalization.DateTimeFormatInfo dtfi.ShortDatePattern = "dd/MM/yyyy" dtfi.DateSeparator = "/" Dim objDate As DateTime = Convert.ToDateTime(strDate, dtfi) cmd.CommandType = CommandType.Text cmd.Parameters.AddWithValue("@f1", tb_eventtitle.Text) cmd.Parameters.AddWithValue("@f2", tb_eventdescription.Text) cmd.Parameters.AddWithValue("@f3", tb_eventdate.Text) cmd.Parameters.AddWithValue("@f4", dd_eventcategory.Text) oleDbConn.Open() cmd.ExecuteNonQuery() System.Threading.Thread.Sleep("2000") Response.Redirect("~/calendar.aspx") End Sub …
vb.net asp.net ms-access calendarextender datetimeformatinfo
我在C#应用程序中有以下代码.
DateTimeFormatInfo.CurrentInfo.DayNames
Run Code Online (Sandbox Code Playgroud)
ReSharper 7.1.1强调了DateTimeFormatInfo.CurrentInfo可能导致空引用异常的事实.
在什么情况下会发生这种情况?或者这只是ReSharper的一个错误,认为你访问的属性的任何对象应该被空检查?
c# resharper nullreferenceexception datetimeformatinfo resharper-7.1