[研究][ASP.NET]判斷非上班時間
2022-04-20
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#
Default.axpx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication2.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" /><br />
<asp:Label ID="Label1" runat="server"></asp:Label><br />
</div>
</form>
</body>
</html> |
Default.aspx.cs
using System;
namespace WebApplication2
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
double nowMillisecond = DateTime.Now.TimeOfDay.TotalSeconds;
//int nowMillisecond = DateTime.Now.Hour * 60 * 60
// + DateTime.Now.Minute * 60 + DateTime.Now.Millisecond;
if (((nowMillisecond >= 21 * 60 * 60) || (nowMillisecond <= 7 * 60 * 60))
|| (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
|| (DateTime.Now.DayOfWeek == DayOfWeek.Saturday))
Label1.Text = "非上班時間";
else
Label1.Text = "上班時間";
//DateTime.Now.TimeOfDay.TotalSeconds;
}
}
}
|
(完)

沒有留言:
張貼留言