当前位置: 首页 > 面试题库 >

SimpleDateFormat和Date:new如何才能简单地报告将来的日期?XSLT,XML1.0,Java

司空学智
2023-03-14
问题内容

我需要在此代码第二部分的当前日期中添加90天。我已经在下面附加了生成的XML(使用xml1.0和xalan
2.7.1),它看起来很棒,我只需要Licensing_End_Window即可阅读今天的90天后的日期,并且无法解决我的一生。请注意,这只是XSLT及其结果XML的片段。

                    <xsl:element name="App_Data">
                    <xsl:attribute name="App">MOD</xsl:attribute> 
                    <xsl:attribute name="Name">Licensing_Window_Start</xsl:attribute> 
                    <xsl:attribute name="Value">
                        <xsl:variable name="s" select="SimpleDateFormat:new('MM-dd-yyyy')"/>
                        <xsl:variable name="Date" select="Date:new()"/>
                        <xsl:choose>
                            <xsl:when test="add:FlightStart"><xsl:value-of select="substring(add:FlightStart,1,10)"/></xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="SimpleDateFormat:format($s,$Date)" />
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                </xsl:element>
                <xsl:element name="App_Data">
                    <xsl:attribute name="App">MOD</xsl:attribute> 
                    <xsl:attribute name="Name">Licensing_Window_End</xsl:attribute> 
                    <xsl:attribute name="Value">
                        <xsl:variable name="s" select="SimpleDateFormat:new('MM-dd-yyyy')"/>
                        <xsl:variable name="Date" select="Date:new()"/>
                        <xsl:choose>
                            <xsl:when test="add:FlightEnd"><xsl:value-of select="substring(add:FlightEnd,1,10)"/></xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="SimpleDateFormat:format($s,$Date)"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                </xsl:element>

产生的XML

 <Name="Licensing_Window_Start" Value="12-10-2014"/><App_Data App="MOD" Name="Licensing_Window_End" Value="12-10-2014"/><App_Data App="MOD"

问题答案:

我看到您正在尝试使用Java扩展来做到这一点。我不知道它是否可以工作以及如何工作,但是我可以建议一个(几乎)XSLT 1.0解决方案。以下样式表:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:variable name="today" select="date:date()" />

<xsl:template match="/">
    <output>
        <start>
            <xsl:value-of select="concat(substring($today, 6, 2), '-', substring($today, 9, 2), '-', substring($today, 1, 4))" />
        </start>
        <end>
            <xsl:call-template name="add-days-to-today">
                <xsl:with-param name="days-to-add" select="90" />
            </xsl:call-template>
        </end>
    </output>
</xsl:template>

<xsl:template name="add-days-to-today">
    <xsl:param name="days-to-add"/>
    <xsl:param name="year" select="substring($today, 1, 4)"/>
    <xsl:param name="month" select="substring($today, 6, 2)"/>
    <xsl:param name="day" select="substring($today, 9, 2)"/>
    <xsl:param name="a" select="floor((14 - $month) div 12)"/>
    <xsl:param name="y" select="$year + 4800 - $a"/>
    <xsl:param name="m" select="$month + 12*$a - 3"/>
    <xsl:param name="JDN" select="$day + floor((153*$m + 2) div 5) + 365*$y + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045 + $days-to-add" />
    <xsl:param name="f" select="$JDN + 1401 + floor((floor((4 * $JDN + 274277) div 146097) * 3) div 4) - 38"/>
    <xsl:param name="e" select="4*$f + 3"/>
    <xsl:param name="g" select="floor(($e mod 1461) div 4)"/>
    <xsl:param name="h" select="5*$g + 2"/>
    <xsl:param name="D" select="floor(($h mod 153) div 5 ) + 1"/>
    <xsl:param name="M" select="(floor($h div 153) + 2) mod 12 + 1"/>
    <xsl:param name="Y" select="floor($e div 1461) - 4716 + floor((14 - $M) div 12)"/>
    <xsl:param name="MM" select="format-number($M, '00')"/>
    <xsl:param name="DD" select="format-number($D, '00')"/>
    <xsl:value-of select="concat($MM, '-', $DD, '-', $Y)" />
</xsl:template>

</xsl:stylesheet>

当应用于任何XML输入(2014年12月11日)时,返回:

<?xml version="1.0" encoding="UTF-8"?>
<output>
   <start>12-11-2014</start>
   <end>03-11-2015</end>
</output>


 类似资料:
  • 本文向大家介绍SQL Server简单实现数据的日报和月报功能,包括了SQL Server简单实现数据的日报和月报功能的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了SQL Server简单实现数据的日报和月报功能。分享给大家供大家参考,具体如下: 希望本文所述对大家SQL Server数据库程序设计有所帮助。

  • 使用指南 - 数据报告 - 来源分析 - 全部来源报告简介 通过来源分析报告,您可以了解您网站上流量的来源分布情况,主要包括直接访问、搜索引擎和外部链接等,帮助您分析哪些来源给您网站带来了更多有效访客,从而合理规划网络推广渠道。 全部来源主要包括直接访问、搜索引擎、搜索词、外部链接、站内访问、指定广告跟踪等。 来源分析报告可以从不同的维度为您提供更详细的数据来源分析: 1、统计指标 在各种来源方式

  • 问题内容: 我正在尝试创建以start_date和end_date为参数的 JR 报告。 查询: 代码: 我们可以将两个参数传递到表中的同一列吗?例如: 问题答案: 您的代码是错误的。 您应该传递如下参数: 您无需添加 到参数名称。 JasperReports 分发包中有很多示例。 您可以查看此样本以获取更多详细信息。

  • 问题内容: 我问如何用Java检测日期是在本周还是下周?但是答案令人困惑,所以现在我想,如果我可以找到过去的星期日和下一个星期日,这周之间的任何一天,以及下一个星期天和下一个星期天之后的任何一天,对吗? 所以我的新问题是:如何用Java获取过去的星期日和即将到来的星期日? 问题答案: 这个怎么样 : 结果 : 前两个之间的任何一天是本周,后两个之间的任何一天都是下周。

  • 问题内容: 我有以下代码片段: 运行此命令时,将其作为输出: 我期望: 我的意思是说我没有达到预期的月份。怎么了 问题答案: 尝试这个: is “month” (not ) is “day” (not ) 全部包含在SimpledocateFormat的javadoc中 仅供参考,你的格式仍然是有效的日期格式的原因是: is “minutes” is “day in year” 此外,你不需要投地

  • 我正在Android中转换字符串到日期对象......该字符串来自服务器,形式为“2014-02-22”或类似的...我想把它转换成我的日期,我可以在我的应用程序中使用…我是用简单的日期格式,解析的方法来转换....但此语句引发分析异常...意思是它不是转换我的字符串..也就是“2014-02-22”……它应该转换,但它不....所以好心帮我一下.....我得到空的响应