C#输入日期获取对应的星期几

菜鸟之——C# DayOfWeek using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DayOfWeek {     class Program     {         static void Main(string[] args)         { 阅读详情

C#输入日期获取对应的星期几

一、建议窗体如下

在这里插入图片描述

二、具体实现代码如下(两种方法,代码中有注释标明)

注:两种分别使用按钮Button和TextBox_KeyDown
具体代码如下:

using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        enum WeekDay { 星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六 };
        private void button1_Click_1(object sender, EventArgs e)
        {//方法1:
            label1.Text = Convert.ToString((WeekDay)Convert.ToDateTime(textBox1.Text).DayOfWeek);
        }
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {//方法2
            if(e.KeyCode == Keys.Enter)
             {
                this.label1.Text = Convert.ToString(Convert.ToDateTime(this.textBox1.Text).ToString("dddd", new System.Globalization.CultureInfo("zh-CN")));
            }
        }
    }
}

三、程序测试

测试截图如下:
在这里插入图片描述

C#实现的根据日期得到今天是星期几 算法如下:    基姆拉尔森计算公式: W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7   在公式中d表示日期中的日数,m表示月份数,y表示年数。注意:在公式中有个与其他公式不同的地方:   把一月和二月看成是上一年的十三月和十四月,例:如果是2004-1-10则换算成:2003-13-10来代入公式计算。 但是在测试的时候发现有点出入,就是公 阅读详情

相关推荐

C#计算天数(星期几)

第一种:给定两个日期计算相隔的天数 例 2017/11/2       2020/3/29 第二种:给定一个日期,求过了Y 年 M 月  D  天   经过了多少天 例 2017/11/2     3年/14个月/53天/

leonardo_Davinci的博客 1956

C#中获取日期对应星期几的三种方法

第一种: string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; string week = Day[Convert.ToInt32(DateTime.Now.DayOfWeek.ToString("d"))].ToString(); lbDay.Text = week;

zhu1991_的博客 3万+

C#中获取任意日期的星期几的方法分享

通过以上三种方法,我们可以方便地获取指定日期的星期几。你可以根据自己的需求选择其中的一种方法来使用。希望本文对你有所帮助!在C#编程中,有时候我们需要获取一个指定日期是星期几。本文将介绍几种实现这一功能的方法,并附带相应的源代码和描述。方法二:使用Calendar类的GetDayOfWeek方法。方法一:使用DateTime结构的DayOfWeek属性。方法三:使用自定义的方法计算。

PkbgRuby的博客 956

js返回当前时间年月日格式

function gettime() { var date = new Date(); var year = date.getFullYear(); var moth = date.getMonth()+1; var dates = date.getDate(); var arr = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];

金鱼记忆大师 944

C# 获取日期对应的星期:DateTime 格式转换示例

在转换过程中,我们还可以指定日期的格式,以适应不同的日期输入形式。在此方法中,我们指定了日期的格式为 “yyyy-MM-dd”,其中 “yyyy” 表示 4 位数的年份,“MM” 表示 2 位数的月份,“dd” 表示 2 位数的日期。本文将介绍如何使用 DateTime 类进行日期格式转换,实现根据日期获取星期的功能。通过以上示例,我们成功地根据指定的日期获取了对应的星期。在实际应用中,我们可以根据需要调整转换格式,以适应不同的日期字符串格式。方法,指定格式为 “dddd”,得到日期对应的星期。

TechBlitzZ的博客 580

C#实现获取当前日期是星期几(附完整源码)

C#实现获取当前日期是星期几(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 557

C#编写一个控制台程序,输入一个日期,输出这一天是星期几。

代码: class Program { static void Main(string[] args) { Console.WriteLine("请输入日期(格式xxxx-xx-xx):"); string date = Console.ReadLine(); DateTime dt = Convert.ToDateTime(date); string week = dt.

InterestAndFun的博客 1870

微信小程序-如何根据缩放屏幕大小自适应icon图标更改marker

微信小程序如何根据用户的缩放屏幕来改变marker图标icon的大小,实现icon自适应屏幕缩放的效果

Bartender_VA11的博客 3994

C#实现的根据年月日计算星期几的函数

  //y-年,m-月,d-日期  string CaculateWeekDay(int y,int m, int d)  {  if(m==1) m=13;  if(m==2) m=14;        int week=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;   string weekstr="";   switch(week)   {    cas

生姜有味 1001

AIDC储能技术:AI数据中心的高效能源解决方案

储能技术作为现代数据中心的核心支撑系统,通过电化学能量存储与释放实现电力供需平衡。其核心原理在于利用电池管理系统(BMS)实现毫秒级响应,配合光伏等可再生能源构成光储融合系统。在AI算力爆发的背景下,AIDC储能系统展现出三大技术价值:应对脉冲式电力需求、保障供电连续性、提升绿色能源占比。典型应用场景包括大模型训练中心、超算设施等对电力质量要求苛刻的环境。当前行业聚焦10C超高倍率电芯和直流侧耦合架构等创新方案,其中磷酸铁锂电池凭借三维极耳设计和液冷系统等技术突破,成为AIDC储能的主流选择。

weixin_29189377的博客 127

ERPS协议原理

目录 1、ERPS概述: 2、ERPS名词概念解释: 3、ERPS协议报文: 4、ERPS单环基本原理: 5、单环多实例原理: 6、多环原理: 1、ERPS概述: ERPS(Ethernet Ring Protection Switching),即以太网多环保护技术,是ITU-T定义的一种二层破环协议标准,标准号为ITU-T G.8032/Y1344,因此又称为G.8032。它定义了RAPS(Ring Auto Protection Switching)协议报文和保护倒换机制。 ERPS目前支持v1和v2两

weixin_44880796的博客 1万+

C# 实验2.基本数据类型应用

答:首先,在 Visual Studio 中创建一个新的 Windows 窗体应用程序项目。在设计器中,将一个名为 txtDate 的 TextBox 控件和一个名为 lblShow 的 Label 控件添加到窗体上。然后,双击 txtDate 以在代码中生成一个事件处理程序。1.设计一个简单的 Windows应用程序,在文本框中随意输入一个日期,单击“确定”时显示“这一天是星期几”3.了解C#的引用类型,理解数据类型转换。1.理解C#的值类型、常量和变量的概念。

weixin_62399938的博客 95

保姆级教程:在RK3588开发板上配置USB-C PD充电(基于HUSB311芯片与DTS详解)

本文详细介绍了在RK3588开发板上配置USB-C PD充电的完整流程,重点解析了HUSB311芯片的硬件原理与DTS安全配置。通过实战案例和调试技巧,帮助开发者避免常见错误,实现稳定可靠的Type-C PD快充功能,适用于从基础开发板到工业设备的多场景需求。

weixin_42552315的博客 525

python根据日期算星期几_python根据日期返回星期几的方法

python根据日期返回星期几的方法本文实例讲述了python根据日期返回星期几的方法。分享给大家供大家参考。具体如下:这个函数给定日期,输出星期几,至于0是星期一还是星期天,这和时区有关,反正我这里是0表示星期一import time,datetimedef get_week_day(date):week_day_dict = {0 : '星期一',1 : '星期二',2 : '星期三',3 :...

weixin_39862382的博客 2876

RTAB-MAP实战:用Realsense D435i在ROS中搭建室内3D地图(附避坑指南)

本文详细介绍了如何在ROS环境下,使用Intel Realsense D435i深度相机和RTAB-MAP算法进行室内3D地图构建的完整实战流程。内容涵盖环境配置、核心节点数据流解析、关键参数调优、地图保存与重定位,并提供了实用的避坑指南,帮助机器人开发者和研究者快速实现稳定的视觉SLAM应用。

weixin_29095049的博客 502

Spring AI Alibaba 1.x 源码分析-架构设计

本文通过分析Spring AI Alibaba 框架的源码,分析出其原理和架构设计,无论是用于项目开发、技术评估还是团队培训都具有重要价值。

program哲学 491

C#输入日期显示该日期当天为星期几

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.W

Zdream的CSDN博客 2144

YOLO26涨点改进 | 全网独家创新,注意力改进篇| SCI一区Top | 引入AFCA自适应细粒度通道注意力,联合建模全局与局部通道依赖关系,适合目标检测、图像去雾、关键点检测、图像分类、图像分割

🔥本文提出了一种基于AFCA(自适应细粒度通道注意力)模块改进的YOLO26目标检测网络。AFCA通过联合建模全局与局部通道依赖关系,实现了更精细的通道注意力分配,能够增强目标相关特征并抑制背景噪声。该模块采用自适应融合策略动态平衡通道权重,在保持轻量级结构的同时,显著提升了小目标和复杂背景下的检测性能。文章详细介绍了AFCA的结构原理、实现优势,并提供了完整的代码实现和YAML配置文件,指导读者如何将该模块集成到YOLO26框架中。实验结果表明,AFCA在检测精度和鲁棒性方面优于传统注意力机制。

Ai缝合怪、助力小伙伴高效发论文 316

用户输入一个日期计算是星期几以及是一年中的第几天

1、 编写程序,用户按“yyyy-MM-dd”格式输入一个日期,程序计算后输出这一天是星期几,并且计算出是一年中的第几天? 下面贴上代码: 计算星期采用的是:基姆拉尔森计算公式 using System; namespace test10 {     class Program     {         //10、 编写程序,该程序启动后用户可以按“yyyy-

mtlmzb的专栏 5067

双馈风机分段控制策略的一次调频模型深度解析

双馈风机分段调频控制策略研究 摘要:针对高比例风电并网导致的系统频率稳定问题,本研究提出一种基于风速分区的双馈风机一次调频控制策略。该策略根据风速区间(低、中、高)特性差异,分别采用:1)低风速区以转子动能控制为主;2)中速区结合超速备用与动能释放;3)高速区引入桨距角协调控制。通过构建包含空气动力学、轴系动态的完整数学模型,验证了分段控制在调频能力(最大提升40%功率支撑)、转速安全范围(控制在0.7-1.2pu)和动态响应速度(200ms内快速响应)等方面的优势。

huanghm88的专栏 349

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

C#获取星期几

第一种:直接获取当前日期是星期几//获取当前日期是星期几 string dt = DateTime.Today.DayOfWeek.ToString(); protected string GetWeek(string dt) {     string week;     //根据取得的英文单词返回汉字     switch (dt)     {      

wph_1129一直为改变|技术blog:wph4u.net 2230

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

c# 根据日期 获取今天星期几

/// /// 根据年月日计算星期几(Label2.Text=CaculateWeekDay(2004,12,9);) /// /// 年 /// 月 /// 日 //

wangzh300的专栏 4152

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

C#——设计一个简单的Windows应用程序,在文本框中随意输入一个日期,单击按钮显示这一天是星期几

首先设计如下界面: 编写如下代码: usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Wi...

lmm0513的博客 1万+

C# 怎么显示中文格式的日期、星期几

//该语句显示的为英文格式 DateTime.Now.DayOfWeek.ToString(); //显示中文格式星期几 "星期" + DateTime.Now.ToString("ddd",new System.Globalization.CultureInfo(

fjyts的专栏 8063
上一篇: C#DataGridView数据导出到Excel
下一篇: C#获取显示器型号信息
CSDNwhyu
博客等级 码龄7年 10粉丝 4原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值