Chinaunix首页 | 论坛 | 博客
  • 博客访问: 543347
  • 博文数量: 67
  • 博客积分: 1625
  • 博客等级: 上尉
  • 技术积分: 1053
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-04 14:40
文章分类

全部博文(67)

文章存档

2012年(67)

分类: Python/Ruby

2012-08-10 14:21:49


  1. import QtQuick 1.0

  2. Item {
  3.     Timer {
  4.         interval: 500; running: true; repeat: true
  5.         onTriggered: time.text = getCurDate().toString()
  6.     }
  7.     function getCurDate()
  8.     {
  9.          var d = new Date();
  10.          var week;
  11.          switch (d.getDay()){
  12.          case 1: week="星期一"; break;
  13.          case 2: week="星期二"; break;
  14.          case 3: week="星期三"; break;
  15.          case 4: week="星期四"; break;
  16.          case 5: week="星期五"; break;
  17.          case 6: week="星期六"; break;
  18.          default: week="星期天";
  19.          }
  20.          var years = d.getFullYear();
  21.          var month = add_zero(d.getMonth()+1);
  22.          var days = add_zero(d.getDate());
  23.          var hours = add_zero(d.getHours());
  24.          var minutes = add_zero(d.getMinutes());
  25.          var seconds=add_zero(d.getSeconds());
  26.          var ndate = years+"-"+month+"-"+days+"\n"+hours+":"+minutes+":"+seconds;
  27.          return ndate;
  28.     }

  29.     function add_zero(temp)
  30.     {
  31.          if(temp<10) return "0"+temp;
  32.          else return temp;
  33.     }


  34.     Text { id: time }
  35. }
运行结果:

还有一个简单的:

  1. import QtQuick 1.0

  2. Item {
  3.     Timer {
  4.         interval: 500; running: true; repeat: true
  5.         onTriggered: time.text = Qt.formatDateTime(new Date(), "dddd\nyyyy-MM-dd\n-MMM-\nhh-mm-ss")
  6.                                                               // 星期 年份 月份 号 大月份
  7.     }

  8.     Text { id: time }
  9. }
运行结果:
阅读(14379) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~