日历日期到儒略日期的转换
Conversion of calendar date to Julian date
请帮助我使用 xslt 将给定日历日期转换为儒略日期 (YYYYMMM) 7 字节格式的代码...
提前致谢!
在 XSLT 2.0 中,带有图片 [Y0001][d001]
的 format-date() 应该可以满足您的需求。
如果您不能使用 XSLT 2.0,请查看您的 XSLT 处理器是否支持 www.exslt.org
中定义的 date/time 扩展
JD Edwards 日期格式(通常被错误地称为JDE Julian 日期格式) 是一种 CYYDDD
格式,其中:
C
是表示世纪的数字:0代表1900-1999年,1代表2000-2099年,以此类推;
YY
表示给定世纪的年份;
DDD
是给定年份中的天数。
因此,例如,2019-07-02
的日期将表示为 119183
。
要使用 XSLT 1.0, 将 YYYY-MM-DD
格式的日期转换为 JD Edwards 日期格式,您可以使用:
<xsl:template name="date-to-JDE">
<xsl:param name="date"/>
<xsl:variable name="year" select="substring($date, 1, 4)"/>
<xsl:variable name="month" select="substring($date, 6, 2)"/>
<xsl:variable name="day" select="substring($date, 9, 2)"/>
<xsl:variable name="C" select="floor($year div 100) - 19"/>
<xsl:variable name="YY" select="$year mod 100"/>
<xsl:variable name="leap" select="not($year mod 4) and $year mod 100 or not($year mod 400)" />
<xsl:variable name="elapsed-months" select="substring('000031059090120151181212243273304334', 3 * ($month - 1) + 1, 3)"/>
<xsl:variable name="DDD" select="$elapsed-months + ($month > 2 and $leap) + $day"/>
<xsl:value-of select="$C * 100000 + $YY * 1000 + $DDD"/>
</xsl:template>
演示:https://xsltfiddle.liberty-development.net/jyRYYj8
已添加:
如果你确实需要YYYYDDD,那么你可以将上面的简化为:
<xsl:template name="date-to-YYYYDDD">
<xsl:param name="date"/>
<xsl:variable name="year" select="substring($date, 1, 4)"/>
<xsl:variable name="month" select="substring($date, 6, 2)"/>
<xsl:variable name="day" select="substring($date, 9, 2)"/>
<xsl:variable name="leap" select="not($year mod 4) and $year mod 100 or not($year mod 400)" />
<xsl:variable name="elapsed-months" select="substring('000031059090120151181212243273304334', 3 * ($month - 1) + 1, 3)"/>
<xsl:variable name="DDD" select="$elapsed-months + ($month > 2 and $leap) + $day"/>
<xsl:value-of select="$year * 1000 + $DDD"/>
</xsl:template>
请帮助我使用 xslt 将给定日历日期转换为儒略日期 (YYYYMMM) 7 字节格式的代码...
提前致谢!
在 XSLT 2.0 中,带有图片 [Y0001][d001]
的 format-date() 应该可以满足您的需求。
如果您不能使用 XSLT 2.0,请查看您的 XSLT 处理器是否支持 www.exslt.org
中定义的 date/time 扩展JD Edwards 日期格式(通常被错误地称为JDE Julian 日期格式) 是一种 CYYDDD
格式,其中:
C
是表示世纪的数字:0代表1900-1999年,1代表2000-2099年,以此类推;YY
表示给定世纪的年份;DDD
是给定年份中的天数。
因此,例如,2019-07-02
的日期将表示为 119183
。
要使用 XSLT 1.0, 将 YYYY-MM-DD
格式的日期转换为 JD Edwards 日期格式,您可以使用:
<xsl:template name="date-to-JDE">
<xsl:param name="date"/>
<xsl:variable name="year" select="substring($date, 1, 4)"/>
<xsl:variable name="month" select="substring($date, 6, 2)"/>
<xsl:variable name="day" select="substring($date, 9, 2)"/>
<xsl:variable name="C" select="floor($year div 100) - 19"/>
<xsl:variable name="YY" select="$year mod 100"/>
<xsl:variable name="leap" select="not($year mod 4) and $year mod 100 or not($year mod 400)" />
<xsl:variable name="elapsed-months" select="substring('000031059090120151181212243273304334', 3 * ($month - 1) + 1, 3)"/>
<xsl:variable name="DDD" select="$elapsed-months + ($month > 2 and $leap) + $day"/>
<xsl:value-of select="$C * 100000 + $YY * 1000 + $DDD"/>
</xsl:template>
演示:https://xsltfiddle.liberty-development.net/jyRYYj8
已添加:
如果你确实需要YYYYDDD,那么你可以将上面的简化为:
<xsl:template name="date-to-YYYYDDD">
<xsl:param name="date"/>
<xsl:variable name="year" select="substring($date, 1, 4)"/>
<xsl:variable name="month" select="substring($date, 6, 2)"/>
<xsl:variable name="day" select="substring($date, 9, 2)"/>
<xsl:variable name="leap" select="not($year mod 4) and $year mod 100 or not($year mod 400)" />
<xsl:variable name="elapsed-months" select="substring('000031059090120151181212243273304334', 3 * ($month - 1) + 1, 3)"/>
<xsl:variable name="DDD" select="$elapsed-months + ($month > 2 and $leap) + $day"/>
<xsl:value-of select="$year * 1000 + $DDD"/>
</xsl:template>