Python将时间为AM的转换为24小时制
2015-12-05 20:03
441 查看
Below is my code , totally C type programmer, no excellent skills.
This is done by someone expert.
We’re in different level.
You find the Python type grammer.
string operation, list convert, map usage, and join, lambda.
import sys #time = input().strip() time = "00:05:45PM" """ I don't know this issue. 12:24:35AM -> 0:24:35 12:24:35PM -> 12:24:35 """ print(time) if time.find("AM") >= 0: time = time.strip("AM") if time == "12:00:00": time = "00:00:00" time = time.split(':') hh = int(time[0]) mm = int(time[1]) ss = int(time[2]) if hh == 12 and (mm > 0 or ss > 0): hh = 0 #print(time) print("%02d:%02d:%02d" % (hh, mm, ss)) else: time = time.strip("PM") time = time.split(':') hh = int(time[0]) mm = int(time[1]) ss = int(time[2]) #print (time[0]) #print (time[1]) #print (time[2]) if hh != 12: hh = hh + 12 print("%02d:%02d:%02d" % (hh, mm, ss))
This is done by someone expert.
We’re in different level.
You find the Python type grammer.
string operation, list convert, map usage, and join, lambda.
ins = input().strip() is_pm = ins[-2:].lower() == 'pm' time_list = list(map(int, ins[:-2].split(':'))) if is_pm and time_list[0] < 12: time_list[0] += 12 if not is_pm and time_list[0] == 12: time_list[0] = 0 print(':'.join(map(lambda x: str(x).rjust(2, '0'), time_list)))
相关文章推荐
- python,random.random()和random.Random()的区别联系
- 实现Python str.split功能的小函数
- python读取图像
- Python爬虫进阶一之爬虫框架Scrapy安装配置
- 定义 Model兼容python2.x和python3.x
- Mac 环境下下配置opencv +python
- python 字符串与16进制互转
- 通过python的obbc模块连接mysql数据库
- Climbing Stairs-python
- Python火车票代码
- Python 异常处理
- Python 文件I/O
- Python 模块
- Python函数
- Python 日期和时间
- Python 字典(Dictionary)
- Python 元组
- 【Python】Python 三种导入模块的方法和区别
- Python爬虫入门七之正则表达式
- python基础教程共60课-第7课if