从Day的整数值获取星期几 [英] Get the Day of a week from integer value of the Day

查看:67
本文介绍了从Day的整数值获取星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将一周中的几天转换为各自的整数值.

I have converted several days of the week to their respective integer values..

例如:星期二,星期四,星期五 2,4,5

现在我需要从整数中恢复过去.

Now I need to get back to the days from the integers.

与我所做的相反.

问题的反面:获取星期几的整数值

是否有一种简单的标准方法来从C#中的整数值中获取星期几,否则我将不得不使用方法来执行手动计算?

推荐答案

尝试以下代码:-

Response.Write(Enum.GetName(typeof(DayOfWeek),5));

输出:

星期五

并且如果必须将整数转换为星期几,请参见以下示例,使用LINQ转换"2,4,5".

and If you have to convert integers to days of week, see following sample to convert "2,4,5″ using LINQ.

var t = string.Join(",",
                 from g in "2,4,5".Split(new char[] { ',' })
                 select Enum.GetName(typeof(DayOfWeek), Convert.ToInt32(g)));
        Response.Write(t);

输出:

Tuesday,Thursday,Friday

有关其他信息:-

http://msdn.microsoft.com/zh-cn/library/system.enum.getname(v = vs.110).aspx

这篇关于从Day的整数值获取星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆