Sometimes there is often a gap of 8 hours between the current time and the current time,
Date Now = new date ();
Now. gettime (); The returned long value is correct, but once I parse now as a string, it will be 8 hours less, so set the following time zone. Keep it for future use.
Private long getnowtime (){
Dateformat format = getdateformat ();
Date Now = new date ();
Log. D ("Joey", "------- now time --- no format:" + now. gettime ());
String now_time = format. Format (now );
Log. D ("Joey", "------- now time:" + now_time );
Return now. gettime ();
// The current time is returned in milliseconds, but the Chinese format is 8 hours less.
}
Private dateformat getdateformat (){
Dateformat my_format = new simpledateformat ("yyyy/mm/dd hh: mm: SS ");
Timezone China = timezone. gettimezone ("Asia/Shanghai ");
My_format.settimezone (China );
Return my_format;
}
Private long getopentime (string date) {// obtain the start time of the activity in the format of yyyy/mm/dd hh: mm: Ss.
// Dateformat format2 = dateformat. getdateinstance ();
// Timezone China = timezone. gettimezone ("Asia/Shanghai ");
// Format2.settimezone (China );
Long a = 0;
Try {
Date date1 = getdateformat (). parse (date );
A = date1.gettime ();
} Catch (parseexception e ){
E. printstacktrace ();
}
Return;
}
In this way, the difference between the current time and the input date will not go wrong.