current_time.svg 1.65 KB
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
  <style>
    polygon { fill: black }

    div {
      color: white;
      font:18px serif;
    }
	.currentDate {
		text-align: center;
	}
	.currentTime {
		text-align: center;
	}
  </style>
  <polygon points="5,5 195,5 195,80 5,80" />

  <!-- Common use case: embed HTML text into SVG -->
  <foreignObject x="5" y="5" width="195" height="80">
    <!--
      In the context of SVG embeded into HTML, the XHTML namespace could
      be avoided, but it is mandatory in the context of an SVG document
    -->
    <div xmlns="http://www.w3.org/1999/xhtml">
      <div id="currentDate" class="currentDate">
	  </div>
	  <div id="currentTime" class="currentTime">
	  </div>
    </div>
	<script>
    var currentDate = document.getElementById("currentDate");
    currentDate.innerHTML = getCurrentDate();

    //封装日期函数
    function getCurrentDate() {
		var date = new Date(); //创建日期对象
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var dates = date.getDate();
        arr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', ]
        var day = date.getDay();
        return year + '年' + month + '月' + dates + '日 ' + arr[day];
    }
	
	function getTime(){
		var date = new Date();
		var hh = date.getHours();
		var mf = date.getMinutes();
		var ss = date.getSeconds();
		mf = mf>10?mf:'0'+mf;
		ss = ss>10?ss:'0'+ss;
		return time = hh+':'+mf+':'+ss;
	}
	setInterval(function(){
		var currentTime = document.getElementById("currentTime");
		currentTime.innerHTML = getTime();
	},1000)
	
	
</script>
  </foreignObject>
</svg>