时间戳转换成标准日期

时间戳好像是13位的纯数字。
如:1596297600000
我只需要年月日。
显示在elementui的日期组件那种格式

 //时间戳转换方法    time:需要被转换的时间戳数字
    formatDate(time) {
      var date=new Date(parseInt(time));
      var year=date.getFullYear();
      var mon = date.getMonth()+1;
      var day = date.getDate();
      return year+'/'+mon+'/'+day;
    },

在MapReduce框架,我们通常会定义两个主要函数:map()函数执行映射操作,reduce()函数执行归约操作。这里,我们将使用Hadoop Streaming API,它允许用户编写简单的脚本作为mapper和reducer。首先,我们将创建一个Python mapper脚本来将Unix时间戳转换为日期,然后创建一个reducer脚本来处理并合并日期。 **Mapper脚本 (mapper.py)**: ```python #!/usr/bin/env python import sys from datetime import datetime # Map function to convert Unix timestamp to ISO date for line in sys.stdin: try: unix_timestamp = int(line.strip()) dt_object = datetime.fromtimestamp(unix_timestamp) iso_date = dt_object.strftime("%Y-%m-%d %H:%M:%S") print(f"{iso_date}\t1") except ValueError: pass # Skip non-integer lines ``` **Reducer脚本 (reducer.py)**: ```python #!/usr/bin/env python import sys current_date = None count = 0 for line in sys.stdin: parts = line.strip().split("\t") if len(parts) != 2: continue date, count_str = parts count = int(count_str) if current_date and current_date == date: count += count else: if current_date: print(f"{current_date}\t{count}") current_date = date count = 1 # Print the last unique date after the loop if current_date: print(f"{current_date}\t{count}") ``` 在实际运行时,你可以这样调用`hadoop streaming`命令: ```shell hadoop jar hadoop-streaming.jar -input input_file.txt \ -mapper mapper.py -reducer reducer.py -output output_dir ``` 这将读取`input_file.txt`的Unix时间戳,通过mapper转换为ISO日期格式,然后由reducer合并并去除重复日期
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值