SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dff.setTimeZone(TimeZone.getTimeZone("GMT+08"));
String ee = dff.format(new Date());
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
String rt = sdf.format(calendar.getTime());
public static String getLocalDatetimeString(String local) {
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(local));
cal.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
String date = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH);
String time = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);
return date + " " + time;
}
String tt = getLocalDatetimeString("GMT+8");
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
public class TimeTest {
/**
* @param args
*/
public static void main(String[] args) {
method1();
method2();
method3();
}
static void method1(){
SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dff.setTimeZone(TimeZone.getTimeZone("GMT+08"));
String ee = dff.format(new Date());
System.out.println("ee="+ee);
}
static void method2(){
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
String rt = sdf.format(calendar.getTime());
System.out.println("TimeTest.method2() rt="+rt);
}
static void method3(){
String local = "GMT+8";
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(local));
cal.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
String date = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH);
String time = cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);
System.out.println("TimeTest.method3() date="+date+",time="+time);
}
}
URL url=new URL("http://www.bjtime.cn");//取得资源对象
URLConnection uc=url.openConnection();//生成连接对象
uc.connect(); //发出连接
long ld=uc.getDate(); //取得网站日期时间
Date date=new Date(ld); //转换为标准时间对象
//分别取得时间中的小时,分钟和秒,并输出
System.out.print(date.getHours()+"时"+date.getMinutes()+"分"+date.getSeconds()+"秒");
LocationManager locMan = (LocationManager) this.getSystemService(MainActivity.LOCATION_SERVICE); //获取最近一次知道的时间 long networkTS = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getTime();
locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); //获取当前时间
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
long time = location.getTime();
Date date = new Date(time);
System.out.println(time + " NETWORK_PROVIDER " + date);
// System.out.println(STANDARD_TIME + " ");
}
/**
*
* @param ts 形如yyyy-MM-dd hh:mm:ss
* @param intervalTime long类型
* @return String HH:mm:ss
*/
@SuppressLint("SimpleDateFormat")
public static String getTime(String ts,long intervalTime){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Timestamp t=null;
String tt="";
try {
t = new Timestamp(format.parse(ts).getTime());
long ss = t.getTime();
long st = ss+intervalTime;
tt= getTime(st);
} catch (java.text.ParseException e) {
e.printStackTrace();
}
return tt;
}
/**
* @param mis
* @return HH:mm:ss
*/
@SuppressLint("SimpleDateFormat")
public static String getTime(long mis){
SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String ee = dff.format(new Date(mis));
return ee.substring(11);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有