一种不太难看的本地化 DayOfWeek 的方法?
using System;
namespace Server.Custom.Extensions
{
public static class FriendlyExtensions
{
public static string Friendly(this DayOfWeek day)
{
if (day == DateTime.Now.DayOfWeek)
return "Hoy";
int dayOfWeek = (int)DateTime.Now.DayOfWeek;
int dayOfEvent = (int)day;
if (dayOfWeek + 1 == dayOfEvent || (dayOfWeek == 6 && dayOfEvent == 0))
return "Mañana";
switch (day)
{
default:
case DayOfWeek.Monday: return "Lunes";
case DayOfWeek.Tuesday: return "Martes";
case DayOfWeek.Wednesday: return "Miercoles";
case DayOfWeek.Thursday: return "Jueves";
case DayOfWeek.Friday: return "Viernes";
case DayOfWeek.Saturday: return "Sabado";
case DayOfWeek.Sunday: return "Domingo";
}
}
}
}
有什么方法可以用文化来本地化它吗?如何? :( 顺便说一句,我也希望它能说“今天”或“明天”,而不仅仅是转换日期
using System;
namespace Server.Custom.Extensions
{
public static class FriendlyExtensions
{
public static string Friendly(this DayOfWeek day)
{
if (day == DateTime.Now.DayOfWeek)
return "Hoy";
int dayOfWeek = (int)DateTime.Now.DayOfWeek;
int dayOfEvent = (int)day;
if (dayOfWeek + 1 == dayOfEvent || (dayOfWeek == 6 && dayOfEvent == 0))
return "Mañana";
switch (day)
{
default:
case DayOfWeek.Monday: return "Lunes";
case DayOfWeek.Tuesday: return "Martes";
case DayOfWeek.Wednesday: return "Miercoles";
case DayOfWeek.Thursday: return "Jueves";
case DayOfWeek.Friday: return "Viernes";
case DayOfWeek.Saturday: return "Sabado";
case DayOfWeek.Sunday: return "Domingo";
}
}
}
}
Is there some way to localize this with Cultures? how? :(
By the way I want it to say "Today" or "Tomomorrow" too, not just convert the days
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或
参考文献:
or
References:
此处(见底部)的这段代码可能会让您进入正确的轨道。
This code from here (see bottom) might put you on the right track.