我想知道是否有一个方法或格式字符串我在.NET中缺少转换以下内容:
1 to 1st
2 to 2nd
3 to 3rd
4 to 4th
11 to 11th
101 to 101st
111 to 111th
Run Code Online (Sandbox Code Playgroud)
这个链接有一个很好的例子,说明了编写自己的函数所涉及的基本原理,但是如果我缺少内置容量,我会更好奇.
解
斯科特汉塞尔曼的回答是公认的,因为它直接回答了这个问题.
但是,对于解决方案,请看这个很好的答案.
任何人请帮助我需要显示日期03/03/2012作为2012年3月3日等
我怎样才能在c#中提到日期格式.
对于2010年11月1日,它应显示为:11月1日
对于2010年11月30日,它应显示为:11月30日
我们可以使用任何日期格式或制作一个自定义函数,返回1 - >'st',2->'nd'3 - >'rd',任何日期no - >'th'.
在标题中,没有人知道是否有在.NET的地方,或第三方库,其中的整数可以转换为自己的"排序"同行.
1 - first
2 - second
3 - third
etc...
Run Code Online (Sandbox Code Playgroud)
我当然可以自己写一个,但如果可能的话,我宁愿重用已经存在的东西.
谢谢.
非常简单的问题,如何使用xslt将数字(1,2,3等)转换为打印友好序数(第1,第2,第3等)?
目前以下工作适用于1-20,但我们可能会看到更多的实体很快就会排名:
<xsl:template name="FormatRanking">
<xsl:param name="Value"></xsl:param>
<xsl:choose>
<xsl:when test="$Value = '1'">
<xsl:value-of select="$Value"/>st
</xsl:when>
<xsl:when test="$Value = '2'">
<xsl:value-of select="$Value"/>nd
</xsl:when>
<xsl:when test="$Value = '3'">
<xsl:value-of select="$Value"/>rd
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$Value"/>th
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
我知道如何做到这一点的唯一方法是改变xsl:when's:
<xsl:when test="$Value = '1'">
<xsl:when test="$Value = '2'">
<xsl:when test="$Value = '3'">
Run Code Online (Sandbox Code Playgroud)
到(甚至不确定这是否正确):
<xsl:when test="$Value = '1' or $Value = '21' or $Value = '31' ...">
<xsl:when test="$Value = '2' or $Value = '22' or $Value = '33' ...">
<xsl:when test="$Value = '3' or $Value …Run Code Online (Sandbox Code Playgroud) 是否有一种简单的方法以第1,第2,第3,......格式显示日期的日期部分?我怀疑通过自定义日期时间格式字符串没有这样做的方法(我会很高兴错了),所以有人实现了这样做的方法吗?
我需要一个函数来在显示像" th"中的" Wednesday June 5th, 2008" 这样的文本时返回几天的后缀.
它只需要工作数字1到31(不需要错误检查)和英语.
是否有内置的VB.NET函数将数字格式化为序数或者我必须自己编写?
我有自己的DateTime变量
7/11/2014
Run Code Online (Sandbox Code Playgroud)
我想将该日期转换为显示为
7th November 2014
Run Code Online (Sandbox Code Playgroud)
我使用什么格式?我试过了,ToLongDateString但它错过了日期的后缀.