获取区域性特定日期2位数年在C# [英] Get culture-specific date with 2 digit year in C#

查看:203
本文介绍了获取区域性特定日期2位数年在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新了一些code表示格式的日期,使用MM / DD / YY的字符串。我需要它是文化的了解,但要保持两位数的年份,以保持日期短。下面是我想出了,但有没有更好的办法?

 字符串DATEFORMAT = culture_Info.DateTimeFormat.ShortDatePattern.Replace(YYYY,YY);
 

解决方案

我不知道有什么办法,没有(和我看的格式相当广泛)。你有什么明显仍有一点在嘴里讨厌的味道,但我认为这是最好的,你可以做的。

I'm updating some code that formats a date to a string using "MM/dd/yy". I need it to be culture aware, but want to keep the two digit year in order to keep the date short. Below is what I came up with, but is there a better way?

string dateFormat = culture_Info.DateTimeFormat.ShortDatePattern.Replace("yyyy", "yy");

解决方案

I don't know of any way, no (and I've looked at the formatting reasonably extensively). What you've got obviously still leaves a bit of a nasty taste in the mouth, but I think it's the best you can do.

这篇关于获取区域性特定日期2位数年在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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