---
title: "jquery flot x轴时间差8小时问题"
author: "lee1177"
date: "2012-06-20T10:56:10Z"
tags: ["flot", "jQuery"]
categories: ["Web前端"]
slug: "jquery-flot-x-8"
draft: false
lastmod: "2012-06-20T10:56:10Z"
id: 1564514
url: "https://lee1177.iteye.com/blog/1564514"
---

使用flot时x轴为时间数据从后台传时间过来，但现实后发现显示的是UTC时间，跟本地时间差8小时，查了下资料用tickFormatter解决了。

```
var options = {
        lines: { show: true },
        points: { show: true },
        grid: { hoverable: true},
        xaxis: { 
        	mode: "time",
        	timeformat: "%H:%M:%S",
        	tickFormatter: function (val, axis) {
	            var d = new Date(val);
	            return d.toLocaleTimeString();//转为当地时间格式
	        }
        }
    };
```