필터 지우기
필터 지우기

help needed in map reduce code.

조회 수: 2 (최근 30일)
naadiya khudabux
naadiya khudabux 2016년 10월 14일
댓글: naadiya khudabux 2016년 10월 14일
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