Android DatePreference 默认值未设置?
如何从 Java 端设置 DatePreference 默认值。
我想“现在”设定日期,
谢谢。
How To Set DatePreference Default Value From Java Side.
I Want Set to Date "Now"
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太确定你在问什么,因为我不知道什么是“DatePreference”,谷歌也不知道。
使用 Java 和 Android,您可以使用多种选项来表示和处理日期/时间数据。要表示“现在”:
您可以使用 java .util.日期。无参数构造函数创建一个 Date 对象,该对象“表示分配它的时间”。
您可以使用java.util.Calendar。 Calendar.getInstance() 返回“设置为默认时区中的当前日期和时间的日历子类实例”。
您可以使用原始长整型值。 System.currentTimeMillis() 返回“当前以毫秒为单位的时间”。
您可以使用 android.text.format.Time ,这是“日历的更快替代品”。构造或以其他方式获取 Time 对象后,调用 setToNow() 将时间设置为“当前时间”。
在 Android 之前,我知道很多人在处理 date/ 时更喜欢使用 Joda-Time Java 中的时间数据。使用 Joda-Time,您可以创建一个新的 joda.time .DateTime 实例,带有无参数构造函数,它代表“默认时区中使用 ISOChronology 的当前系统毫秒时间”。
我还建议在使用时查看 android.os.SystemClock 文档Android 中的日期/时间事件。
I'm not exactly sure what you're asking about, as I don't know what a "DatePreference" is, and neither does Google.
With Java and Android, you have a few options for representing and working with date/time data. To represent "Now":
You could use java.util.Date. The no argument constructor creates a Date object that "represents the time at which it was allocated".
You could use java.util.Calendar. Calendar.getInstance() returns "a Calendar subclass instance set to the current date and time in the default Timezone".
You could use a primitive long value. System.currentTimeMillis() returns "the current time in milliseconds".
You could use android.text.format.Time, which is "a faster replacement for" Calendar. After constructing or otherwise obtaining a Time object, call setToNow() to set the time "to the current time".
Before Android, I know a lot of folks preferred to use Joda-Time when working with date/time data in Java. With Joda-Time, you could create a new joda.time.DateTime instance with the no argument constructor, which would then represent "the current system millisecond time using ISOChronology in the default time zone".
I also recommend reviewing the android.os.SystemClock documentation, when working with date/time events in Android.
我找到了解决方案
dpDate.setDate(tools.NowDate());
I Found Solution This
dpDate.setDate(tools.NowDate());