Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 日期及日期;时间间隔 var current_date=新日期(); var current_timezone=current_date.getTimezoneOffset(); document.getElementById(“inpHide”).value=当前时区*-1; document.getElementById(“inHide1”).value=当前\日期; 受保护的无效按钮1\u单击(对象发送者,事件参数e) { Label1.Text=inpHide.Value.Trim(); Label2.Text=inpHide1.Value.Trim(); Label3.Text=Label2.Text; }_C#_Asp.net_Timezone - Fatal编程技术网

C# 日期及日期;时间间隔 var current_date=新日期(); var current_timezone=current_date.getTimezoneOffset(); document.getElementById(“inpHide”).value=当前时区*-1; document.getElementById(“inHide1”).value=当前\日期; 受保护的无效按钮1\u单击(对象发送者,事件参数e) { Label1.Text=inpHide.Value.Trim(); Label2.Text=inpHide1.Value.Trim(); Label3.Text=Label2.Text; }

C# 日期及日期;时间间隔 var current_date=新日期(); var current_timezone=current_date.getTimezoneOffset(); document.getElementById(“inpHide”).value=当前时区*-1; document.getElementById(“inHide1”).value=当前\日期; 受保护的无效按钮1\u单击(对象发送者,事件参数e) { Label1.Text=inpHide.Value.Trim(); Label2.Text=inpHide1.Value.Trim(); Label3.Text=Label2.Text; },c#,asp.net,timezone,C#,Asp.net,Timezone,我不确定您使用的是哪种编程语言,但大多数语言都有一个函数,可以在空白处打断字符串。您可以这样打断字符串,然后取出日期元素并使用它们。您应该看看 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server">

我不确定您使用的是哪种编程语言,但大多数语言都有一个函数,可以在空白处打断字符串。您可以这样打断字符串,然后取出日期元素并使用它们。

您应该看看

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="inpHide" type="hidden" runat="server" />
        <input id="inpHide1" type="hidden" runat="server" />
        <asp:Label ID="Label1" runat="server"></asp:Label>
        <asp:Label ID="Label2" runat="server"></asp:Label>
        <asp:Label ID="Label3" runat="server"></asp:Label>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Width="100px" Height="30px" Text="Button" />
    </div>
    <script language="javascript" type="text/javascript">
        var current_date = new Date();
        var current_timezone = current_date.getTimezoneOffset();
        document.getElementById("inpHide").value = current_timezone * -1;
        document.getElementById("inpHide1").value = current_date;
        </script>
</body>
</html>

protected void Button1_Click(object sender, EventArgs e)
{
        Label1.Text = inpHide.Value.Trim();
            Label2.Text = inpHide1.Value.Trim();
            Label3.Text = Label2.Text;
}

您应该特别注意parse函数和各种ToString函数,注意要传递的字符串格式(或根据当前的文化),以确保获得您期望的格式。

我使用字符串格式,如www.csharp-examples.net页面所述:

DateTime dt;
string Temp1 = "Your Date";
if (Temp1.LastIndexOf("GMT") > 0)
{
    Temp1 = Temp1.Remove(Temp1.LastIndexOf("GMT"));
}
Temp1 = "Wed May 25 23:43:31 UTC+0900 2011";
if (Temp1.LastIndexOf("UTC") > 0)
{
     Temp1 = Temp1.Remove(Temp1.LastIndexOf("UTC"), 9);
     string[] split = Temp1.Split(' ');
     Temp1 = split[0] + " " + split[1] + " " + split[2] + " " + split[4] + " " + split[3];
}
if (DateTime.TryParse(Temp1, out dt))
{
     // If it is a valid date
     string date = dt.ToShortDateString();
     string time = dt.ToShortTimeString();
}

这里并不清楚您的输入和输出类型。请您澄清一下好吗?您好@astay13您是对的,还不太清楚,但我相信Arun正在使用c#/asp.net,正如它在问题标签中所说的那样。string Temp1=“Wed May 25 2011 19:15:49 GMT+0530(印度标准时间)”;从上面的字符串Temp1中,我需要单独将“2011年5月25日”与Temp1分开。因此,我可以字符串Temp2=“25/05/2011”;您提到的格式应该在修剪后GMT部分并最终在验证后准备。对不起,SQL,您的代码工作不正常。在调试过程中,函数没有进入“if”循环。很抱歉,给出了错误的答案,您的代码正在工作。如果假设字符串Temp1=“Wed May 25 23:43:31 UTC+0900 2011”。。您的代码在那个时候不起作用。我同意您的回答SQL,但GMT中仍然存在一个问题,在它之前的一年,但在UTC中,在它之后的一年。如果我使用您的代码,我的代码适用于GMT,但不适用于UTC的年份检测。不必担心@Arun,我希望它能有所帮助。我的代码是string sample=“Wed May 25 23:43:31 UTC+0900 2011”;string.format对于上述代码无法正常工作。
String.Format("{0:t}", dt);  // "4:05 PM"                         ShortTime
String.Format("{0:d}", dt);  // "3/9/2008"                        ShortDate