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

回答(1 个)

Guillaume
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?
  1 个评论
naadiya khudabux
naadiya khudabux 2016-10-14
No I just want to convert to local time zone and save as date time vector

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by