help needed in map reduce code.

1 Ansicht (letzte 30 Tage)
naadiya khudabux
naadiya khudabux am 14 Okt. 2016
Kommentiert: naadiya khudabux am 14 Okt. 2016
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

Antworten (1)

Guillaume
Guillaume am 14 Okt. 2016
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 Kommentar
naadiya khudabux
naadiya khudabux am 14 Okt. 2016
No I just want to convert to local time zone and save as date time vector

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by