如何从其他客户端获取YYYY-MM-DD格式的日期?

时间:2018-05-04 06:34:10

标签: java postgresql rest date postman

我有一个表格,其中包含' date'的类型的created_date列。

执行此查询时

select created_date as "Date" myTable

输出是:

2018-02-23 05:34:12 //Not desired output

所以,当我执行这个查询时

select (created_date::TIMESTAMP::DATE) AS "Date" from myTable

输出是:

2018-02-23 // Desired Output

但是当我尝试通过rest api从休息客户端(邮递员)执行此查询时,问题就出现了。现在响应控制台上的输出是在Unix时间戳中。

1519344000000

但我也想以相同的格式YYYY-MM-DD作为回应。

2 个答案:

答案 0 :(得分:1)

如果您的其他人将日期转换为unix时间戳,您可以尝试将日期转换为文本以避免转换,例如:

select (created_date::TIMESTAMP::DATE::text) AS "Date" from myTable

答案 1 :(得分:0)

如果我们需要日期为特定格式,请说明“DD / MM / YYYY”

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:flow="http://www.springframework.org/schema/webflow-config"
    xmlns:faces="http://www.springframework.org/schema/faces"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow-config 
    http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.4.xsd 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/faces 
    http://www.springframework.org/schema/faces/spring-faces.xsd">

    <bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener" />

    <flow:flow-executor id="flowExecutor">
            <flow:flow-execution-listeners>
                <flow:listener ref="facesContextListener"/>
            </flow:flow-execution-listeners>
    </flow:flow-executor>   

    <flow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices">
        <flow:flow-location id="hello" path="/WEB-INF/flows/hello-flow.xml" />
    </flow:flow-registry>

    <!-- Configures the Spring Web Flow JSF integration -->
    <faces:flow-builder-services id="facesFlowBuilderServices" development="true" />

    <faces:resources/>

    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
        <property name="order" value="1"/>
        <property name="flowRegistry" ref="flowRegistry" />
        <property name="defaultHandler">
            <bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
        </property>
    </bean>

    <bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
        <property name="flowExecutor" ref="flowExecutor" />
    </bean>

    <bean id="faceletsViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
        <property name="prefix" value="/WEB-INF/" />
        <property name="suffix" value=".xhtml" />
    </bean>

    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

</beans>