C# 获取当前是星期几的两种方法
C#的功能很强大,却没有直接提供面向汉字文化的开发倾向
比如我现在要说的获取当前的星期我提供两种方法:
①,DateTime.Now.DayOfWeek ,查询MSDN可以知道该属性返回的结果是:
//
// 摘要:
// 获取此实例所表示的日期是星期几。
//
// 返回结果:
// 一个 System.DayOfWeek 枚举常数,它指示星期几。该属性值的范围从零(表示星期日)到六(表示星期六)。
public DayOfWeek DayOfWeek
{
get;
}
依据这个我们想见该属性提供了从星期日到星期六的位置,也就是说是枚举,枚举结合数组不就可以提取我们想要的数据了吗!代码如下:
public string Week()
{
string[] weekdays ={ "星期日" ,"星期一" ,"星期二" ,"星期三" ,"星期四" ,"星期五" ,"星期六" };
string week=weekdays[Convert.ToInt32(DateTime.Now.DayOfWeek)];
return week;
}
你只要调用该方法:Week()就可以得到当前星期几的汉字表示 Lable1.Text=Week();
②第二种方法是直接根据星期的数目比较小还可以直接转化,这时候我们可以用switch关键字代码如下:
public string Week(string weekName)
{
string week;
switch(weekName)
{
相关文档:
Paging long articles in ASP.NET using C#
Long articles are better broken into bite-sized chunks over several pages. With static HTML, this is easily achieved by dividing the article into logical separations and creating separate .htm files for each. Here's how to do it using C# for an article that ......
SQLite 是一个嵌入式的联系数据库系统,运用十分广泛。在一些数据量不大的运用 程序中,假如运用 SQLite可以极大的降低部署时的工作量。 要在C#中运用 SQLite也很基本,只要找一个C#的wrapper就可以了,例如,我运用的就是来自
http://sqlite.phxsoftware.com/ 的一个dll,System.Data.SQLite. 下载下来的文件是 ......
C#中操作Oracle时的SQL语句参数的用法
OracleTransaction myTrans ;
conn.Open();
myTrans =conn.BeginTransaction(IsolationLevel.ReadCommitted) ......
using System;
using System.IO;
using System.Windows.Forms;
using Access = Microsoft.Office.Interop.Access;
// 添加引用->.NET-> dao,Microsoft.Office.Interop.Access
namespace WinFormAccess
{
public partial class FormAccess : Form
{
&nbs ......
public void SetWindowRegion()
{
System.Drawing.Drawing2D.GraphicsPath FormPath;
FormPath =
new System.Drawing.Drawing2D.GraphicsPath();
Rectangle
rect=ne ......