所以我试着制作一个脚本,将"properties{"CreationDate"]
后面的项目转换为Joda-Time。但我一直都有错误。
Creationdate是我程序中的属性字段,日期为2014年2月25日10:20。但我想在Joba时间。像这样:2014年M2 25,周三10:20:09 GMT + 02:00
所以我不能创建一个脚本,我输入日期,因为日期在创建日期之后。这一天背后会有很多日期。
我无法在代码中使用日期,因为“creationdate”背后会有很多差异日期
require 'date'
items = $current_selected_items
items.each do |email|
properties = email.getProperties
date_time = properties["CreationDate"]
date_time.strftime("%m/%d/%Y %H:%M:%S")
date_time.strftime("%Y M%m %d, %a %H:%M:%S %Z")
end
错误:
NoMethodError: undefined method `strftime' for "2/25/2014 10:20":String
Did you mean? strip
block in (root) at <script>:6
<main> at <script>:3
Script failed due to an error:
org.jruby.embed.EvalFailedException: (NoMethodError) undefined method `strftime' for "2/25/2014 10:20":String
Did you mean? strip
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:131)
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:90)
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:142)
at sun.reflect.GeneratedMethodAccessor119.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.nuix.script.e.a(SourceFile:59)
at java.security.AccessController.doPrivileged(Native Method)
at com.nuix.script.e.a(SourceFile:56)
at com.sun.proxy.$Proxy46.eval(Unknown Source)
at com.nuix.script.j.a(SourceFile:53)
at com.nuix.investigator.script.m.e(SourceFile:326)
at com.nuix.investigator.script.m.c(SourceFile:277)
at com.nuix.investigator.script.m.doInBackground(SourceFile:180)
at javax.swing.SwingWorker$1.call(SwingWorker.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at javax.swing.SwingWorker.run(SwingWorker.java:334)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `strftime' for "2/25/2014 10:20":String
Did you mean? strip
at RUBY.block in (root)(<script>:6)
at RUBY.<main>(<script>:3)
答案 0 :(得分:1)
您使用strftime的变量是一个String,这意味着您必须转换它才能在其上使用strftime。
您可以使用strptime传递正确的格式,类似于您在“date_time.strftime("%m/%d/%Y %H:%M:%S")
”中使用的格式,请尝试:
require 'date'
string = DateTime.strptime(properties['CreationDate'], '%d/%M/%Y %H:%M')
puts string.strftime("%Y M%m %d, %a %H:%M:%S %Z")