我有一个原始的SQL查询返回一个日期时间字段,我想返回一个带有这些结果的json.
如果我把返回值我抱怨:
(Poison.EncodeError) unable to encode value: {{2017, 3, 21}, {0, 0, 0, 0}}
如果我尝试使用Timex
以下方法将其转换为字符串:
Timex.format!(Ecto.DateTime.from_erl(datetime_field), "%Y-%m-%d %H:%M:%S", :strftime)
我明白了:
** (FunctionClauseError) no function clause matching in Ecto.DateTime.from_erl/1
如果我跳过这from_erl
部分:
Timex.format!(datetime_field, "%Y-%m-%d %H:%M:%S", :strftime)
我明白了:
** (Poison.EncodeError) unable to encode value: {:error, :invalid_date}
假设我使用Timex的方式如下:
use Timex
Interval.new(from: ~D[2016-03-03], until: [days: 3])
%Elixir.Timex.Interval{from: ~N[2016-03-03 00:00:00], left_open: false, right_open: true, step: [days: 1], until: ~N[2016-03-06 00:00:00]}
Run Code Online (Sandbox Code Playgroud)
我想生成日期列表,间隔一天。我如何从清单转到清单?
我尝试启动Spring Web应用程序时收到以下错误消息:
2012-04-12 13:53:20,491 ERROR [org.springframework.web.servlet.DispatcherServlet] -
Context initialization failed
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [timex-servlet.properties] cannot be opened because it does not exist
java.io.FileNotFoundException: class path resource [timex-servlet.properties] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:137)
at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:172)
Run Code Online (Sandbox Code Playgroud)
我正在通过eclipse运行Tomcat(版本6.x).我尝试将timex-servlet.properties放在以下目录中,但无济于事:
WebContent\WEB-INF
WebContent\WEB-INF\classes
WebContent\
Run Code Online (Sandbox Code Playgroud)
以下是timex-servlet.xml中timex-servlet.properties的引用:
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"
value="timex-servlet.properties" />
</bean>
Run Code Online (Sandbox Code Playgroud)
有几个SO线程处理相同的消息,表示放置类路径:在属性文件引用前面.所以我尝试了以下,但也没有用:
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"
value="classpath:timex-servlet.properties" />
</bean>
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取一个亚秒级部分中只有3位数字的日期时间。
使用timex,我得到以下结果:
iex(12)> {:ok, date} = Timex.format(Timex.shift(Timex.local, days: 16), "{ISO:Extended}")
{:ok, "2017-04-22T09:00:44.403879+03:00"}
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到这样的:
{:OK, “2017-04-22T09:00:44 403 +03:00”}?
我正在尝试将Timex模块格式化为某种方式.我想要今天的约会.但我希望它的格式如下:
2017年12月12日.
年/分钟/天
在ruby中我会去strftime类,但我不知道如何使用Elixir:
目前的尝试:
Timex.local => #DateTime<2017-12-12 19:57:17.232916-05:00 EST America/Detroit>
Run Code Online (Sandbox Code Playgroud)
我该如何处理并格式化我指定的方式?