我的问题采用了一般性方面,比较了How to remove time-field string from a date-as-character variable?提出的问题。
事实上,假设我有这个日期类型变量:
> head(DataDia$Date)
[1] "2016-09-13 15:56:30.827" "2016-12-12 13:39:17.537" "2016-09-16 21:57:24.977" "2016-09-23 11:19:22.010"
[5] "2017-01-11 20:06:58.490" "2016-10-21 23:40:43.927"
如何删除所有时间字段字符串并保留日期格式。所以我明白了:
> head(DataDia$Date)
[1] "2016-09-13" "2016-12-12" "2016-09-16" "2016-09-23"
[5] "2017-01-11" "2016-10-21"
请注意,我正在处理数据表。所以我需要一种使用data.table的方法 操作
答案 0 :(得分:1)
只需使用as.Date(DataDia$Date)
。
答案 1 :(得分:1)
您可以使用:
** Activity (main) Pause, UserClosed = false **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Service (httputils2service) Start **
** Activity (pagelogin) Create, isFirst = true **
** Activity (pagelogin) Resume **
** Activity (pagelogin) Pause, UserClosed = true **
** Activity (main) Create, isFirst = false **
Error occurred on line: 131 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:208)
at wanda.absen.main._activity_create(main.java:546)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at wanda.absen.main.afterFirstLayout(main.java:102)
at wanda.absen.main.access$000(main.java:17)
at wanda.absen.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6205)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
... 18 more
Caused by: java.lang.NoSuchFieldError: No field abc_text_cursor_material of type I in class Landroid/support/v7/appcompat/R$drawable; or its superclasses (declaration of 'android.support.v7.appcompat.R$drawable' appears in /data/app/wanda.absen-1/base.apk)
at android.support.v7.internal.widget.TintManager.<clinit>(TintManager.java:90)
at android.support.v7.internal.widget.TintManager.get(TintManager.java:154)
at android.support.v7.internal.widget.TintTypedArray.getTintManager(TintTypedArray.java:192)
at android.support.v7.internal.widget.TintTypedArray.getDrawable(TintTypedArray.java:62)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:265)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:207)
at android.support.v7.widget.Toolbar.<init>(Toolbar.java:203)
at de.amberhome.objects.appcompat.ACToolbarDarkWrapper.innerInitialize(ACToolbarDarkWrapper.java:27)
at anywheresoftware.b4a.objects.ViewWrapper.Initialize(ViewWrapper.java:65)
at de.amberhome.objects.appcompat.ACToolBarWrapper.Initialize(ACToolBarWrapper.java:45)
at de.amberhome.objects.appcompat.ACToolBarWrapper._initialize(ACToolBarWrapper.java:77)
... 21 more
** Activity (main) Resume **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
答案 2 :(得分:0)
合并as.Date
和as.character
x = c("2016-09-13 15:56:30.827", "2016-12-12 13:39:17.537", "2016-09-16 21:57:24.977", "2016-09-23 11:19:22.010",
"2017-01-11 20:06:58.490", "2016-10-21 23:40:43.927")
y = as.character(as.Date(x, format = "%Y-%m-%d"))
y
[1] "2016-09-13" "2016-12-12" "2016-09-16" "2016-09-23" "2017-01-11" "2016-10-21"