2003-07-16T01:24:32Z这是什么时间格式,用java怎样获取这样的时间?r
这是标准的XML Schema的"日期型数据格式”
T是代表后面跟着“时间”。Z代表0时区,或者叫UTC统一时间。
国内常见于MS Office Excel电子表格XML中的时间格式。
Java用SimpleTimeFormat可以随意处理这样的时间文本
//我实现一个时钟窗口程序给你了,好让你更容易理解,希望对你有帮助。
import javaawt;
import javaawtevent;
import javautil;
//世界时钟
public class TimerTest {
public static void main(String[] args) {
new TimerTestFrame("世界时钟");
}
}
class TimerTestFrame extends Frame {
/
/
private static final long serialVersionUID = 1L;
public TimerTestFrame(String s) {
super(s);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
Systemexit(0);
}
});
setLayout(new GridLayout(2, 6));
ClockCanvas clk1 = new ClockCanvas("北京", "GMT+8"); // 创建时钟
ClockCanvas clk2 = new ClockCanvas("巴黎", "GMT+2");
ClockCanvas clk3 = new ClockCanvas("华盛顿", "GMT-4");
ClockCanvas clk4 = new ClockCanvas("洛衫矶", "GMT-7");
ClockCanvas clk5 = new ClockCanvas("伦敦", "GMT+1");
ClockCanvas clk6 = new ClockCanvas("芝加哥", "GMT-5");
add(clk1);
add(clk2);
add(clk3);
add(clk4);
add(clk5);
add(clk6);
setSize(500, 350); // 设置框架宽高
setVisible(true);
}
}
class ClockCanvas extends Canvas implements Runnable {
/
/
private static final long serialVersionUID = 1L;
private int seconds = 0;
private String city;
private GregorianCalendar calendar;
Thread t;
public ClockCanvas(String c, String tz) {
city = c;
//也可以通过TimeZonesetTimeZone(String n)函数改变时区,n为时区参数名。
calendar = new GregorianCalendar(TimeZonegetTimeZone(tz));
t = new Thread(this);
tstart();
setSize(125, 125); // 设置画布大小
setBackground(Colorblack);
}
// 重写父类的方法绘制时钟图形
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
BasicStroke bstroke = new BasicStroke(20f);
g2dsetStroke(bstroke);
g2dsetColor(Colorgreen);
g2ddrawOval(0, 0, 100, 100);
bstroke = new BasicStroke(50f);
g2dsetStroke(bstroke);
g2ddrawLine(50, 0, 50, 5);
g2ddrawLine(0, 50, 5, 50);
g2ddrawLine(50, 95, 50, 98);
g2ddrawLine(95, 50, 98, 50);
double hourAngle = 2 MathPI (seconds - 3 60 60)
/ (12 60 60);
double minuteAngle = 2 MathPI (seconds - 15 60) / (60 60);
double secondAngle = 2 MathPI (seconds - 15) / (60);
bstroke = new BasicStroke(50f);
g2dsetStroke(bstroke);
g2ddrawLine(50, 50, 50 + (int) (30 Mathcos(hourAngle)),
50 + (int) (30 Mathsin(hourAngle)));
bstroke = new BasicStroke(30f);
g2dsetStroke(bstroke);
g2ddrawLine(50, 50, 50 + (int) (40 Mathcos(minuteAngle)),
50 + (int) (40 Mathsin(minuteAngle)));
bstroke = new BasicStroke(10f);
g2dsetStroke(bstroke);
g2ddrawLine(50, 50, 50 + (int) (45 Mathcos(secondAngle)),
50 + (int) (45 Mathsin(secondAngle)));
g2dsetColor(Colorred);
g2ddrawString(city, 35, 115);
}
public void timeElapsed() {
//new Date()获得当前时间
Systemoutprintln(new Date());
calendarsetTime(new Date());
seconds = calendarget(CalendarHOUR) 60 60
+ calendarget(CalendarMINUTE) 60
+ calendarget(CalendarSECOND);
}
public void run() {
try {
while (true) {
Threadsleep(300);
timeElapsed();
repaint();
}
} catch (InterruptedException e) {
}
}
}
PHP 的 time() 函数返回的结果是 Unix 时间戳,值的单位是秒;
Java 中 SystemcurrentTimeMillis() 返回的结果,值的单位是毫秒。
那么很容易就知道,除以 1000 就行了嘛:
int seconds = SystemcurrentTimeMillis() / 1000;123String date = "20151101095440";String reg = "(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})";date = datereplaceAll(reg, "$1-$2-$3 $4:$5:$6")。
1、java
Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
2、技术优势
与传统程序不同,Sun 公司在推出 Java 之际就将其作为一种开放的技术。全球数以万计的 Java 开发公司被要求所设计的 Java软件必须相互兼容。
0条评论