I have an epoch 1362873600 and I only care about the date portion, not the time.

My goal is to get: 03/10/13

I'm doing the following:

var dateFormatter = new google.visualization.DateFormat({formatType: 'short'});
dateFormatter.formatValue(epochValue);

I've tried with epochValue as a string and as an int.

Both yield: Object 1362873600 has no method 'getTimezoneOffset'

Is there perhaps an option I can use to ignore the timezone part? What is it that formatValue is expecting that would have this getTimezoneOffset method? The documentation just says 'value'.

有帮助吗?

解决方案

It looks like formatValue is expecting a Date object. You can construct one if you know the epoch with new Date(epoch). After you create that object, you should be able to pass it to formatValue and get the value you're expecting.

var dateFormatter = new google.visualization.DateFormat({formatType: 'short'});
var result = dateFormatter.formatValue(new Date(epochValue));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top