help needed in map reduce code.
1 次查看(过去 30 天)
显示 更早的评论
hello .. i am trying to convert the UTC to GMT data format with MapReduce on desktop platform.i want to convert the time into datetime format.like this
2016-25-07 01:26:40
2016-25-07 01:26:40
2016-25-07 01:26:40
2016-25-07 01:26:40
2016-25-07 01:26:40
2016-25-07 04:13:20
2016-25-07 04:13:20
2016-25-07 04:13:20
2016-25-07 01:26:40
2016-25-07 01:26:40
2016-25-07 01:26:40
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
2016-25-07 07:00:00
i am getting wrong results from my code. can someone help me
>> read(outds)
ans =
Key Value
______ __________________
'date' [18598x1 datetime]
end
function Map(data, info, intermKVStore)
%datetime = data.RequestTime(~isnan(data.RequestTime));
dateformated=datetime(data.RequestTime/1000,'ConvertFrom','posixTime',...
'TimeZone','Asia/Hong_Kong','Format','dd-MMM-yyyy HH:mm:ss.SSS')
add(intermKVStore, 'datetime', dateformated);
end
function reduce(intermKey, intermValIter, outKVStore)
date = 0;
while hasnext(intermValIter)
date = date + getnext(intermValIter);
end
add(outKVStore,'date',date);
end
0 个评论
回答(1 个)
Guillaume
2016-10-14
If your input is in UTC and you want the datetime objects to display time in your local timezone, you first need to construct the datetime object in UTC timezone then switch to your local one:
dateformated=datetime(data.RequestTime/1000,'ConvertFrom','posixTime',...
'TimeZone','UTC','Format','dd-MMM-yyyy HH:mm:ss.SSS'); %read data as Posix UTC
dateformated.Timezone = ''Asia/Hong_Kong'; %switch to new timezone. dateformated is adjusted accordingly
Note: Is your purpose really to add all the dates together? If so, why don't you first do it in the map function to reduce memory usage?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MapReduce 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!