How To Set DatePreferenc开发者_C百科e Default Value From Java Side.
I Want Set to Date "Now"
thanks.
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.
I Found Solution This
dpDate.setDate(tools.NowDate());
精彩评论