Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1839366
  • 博文数量: 333
  • 博客积分: 10791
  • 博客等级: 上将
  • 技术积分: 4314
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-08 07:39
文章分类

全部博文(333)

文章存档

2015年(1)

2011年(116)

2010年(187)

2009年(25)

2008年(3)

2007年(1)

分类: C/C++

2010-11-16 14:50:29

c时间戳及格式化

#include <stdio.h>
#include <stdlib.h>

int
main()
{
    time_t t;


    time(&t);

    printf("time_stmp: %d\n", (int)t);

    return 0;
}




java时间戳及格式化

import java.sql.Date;
import java.text.*;

public class DateFormat {
 public static void main(String[] args) {
  // currentTimeMillis 返回以毫秒为单位的时间


  long time = System.currentTimeMillis();
  time /= 1000;
  Date d = new Date(time);
  System.out.println(d);
  System.out.println(DateFormat.format(d));
 }

 public static String format(Date date) {
  SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
  String s = sf.format(date);
  return s;
 }
}


阅读(1033) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~