# 1.使用Python获取系统当前时间
print('---------下面是方法1-----------')
import time
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))

print('---------下面是方法2-----------')
import datetime
curr_time = datetime.datetime.now()
print(curr_time)
print(curr_time.date())
print(curr_time.year)
print(curr_time.month)
print(curr_time.day)
print(curr_time.hour)
print(curr_time.minute)
print(curr_time.second)

# 2.时间类型转换
# datetime-->str
# 获取系统当前时间,并转换成字符串类型的指定格式
print('---------datetime转换成str----------')
time_date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(time_date)
print(type(time_date))

# str-->datetime
print('---------str转换成datetime----------')
time_str = '2022-01-25 15:59:58'
curr_time = datetime.datetime.strptime(time_str, '%Y-%m-%d %H:%M:%S')
print(curr_time)
print(type(curr_time))

Python获取系统当前时间并进行类型转换的更多相关文章

  1. python获取系统开机时间

    import psutil import time time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(psutil.boot_time()))

  2. java获取系统指定时间年月日

    java获取系统指定时间年月日 private String setDateTime(String falg) { Calendar c = Calendar.getInstance(); c.set ...

  3. Unity3D获取系统当前时间,并格式化显示

    Unity 获取系统当前时间,并格式化显示.通过“System.DateTime”获取系统当前的时间,然后通过格式化把获得的时间格式化显示出来,具体如下: 1.打开Unity,新建一个空工程,Unit ...

  4. Oracle,MySQL,sqlserver三大数据库如何获取系统当前时间

    Oracle中如何获取系统当前时间:用SYSDATE() MySQL中获取系统当前时间主要有以下几点: (1)now()函数以('YYYY-MM-dd HH:mm:SS')返回当前的日期时间,可以直接 ...

  5. java 获取系统当前时间并格式化

      java 获取系统当前时间并格式化 CreateTime--2018年5月9日11:41:00 Author:Marydon 实现方式有三种 updateTime--2018年7月23日09点32 ...

  6. 使用js时,如何获取系统当前时间并且得到格式为"yyyy年MM月"的日期

    1.使用js时,如何获取系统当前时间并且得到格式为"yyyy年MM月"的日期: 1 var newdate = new Date(); 2 var nowyear = newdat ...

  7. C++ 获取系统当前时间(日历时)

    获取系统当前时间(日历时) //Linux & C++11 #include <chrono> #include <ctime> using namespace std ...

  8. android service 样例(电话录音和获取系统当前时间)

    关于android service 的具体解释请參考: android四大组件--android service具体解释.以下将用两个实例具体呈现Android Service的两种实现. 一个是st ...

  9. C# 获取系统开机时间

    原文:C# 获取系统开机时间 ///         ///  获取系统开机时间          ///         ///         private DateTime GetComput ...

  10. C/C++获取系统当前时间

    C/C++获取系统当前时间   C库中与系统时间相关的函数定义在<time.h>头文件中, C++定义在<ctime>头文件中. 一.time(time_t*)函数 函数定义如 ...

随机推荐

  1. 通知短信 API 接入全流程(超详细整理)

    随着移动互联网和智能手机的普及,短信成为了一种便捷.快速且有效的通信方式,尤其在向用户发送重要信息或提醒方面具有很大的优势. 本文将会深入探讨如何在程序中接入通知短信 API 实现短信通知功能,此外, ...

  2. 一次Feign使用的案例

    项目名称 projectName Maven架构 l  ProjectName-项目名称,项目父工程 projectName-api-提供给外部组件使用的接口 common-一些基本共用的类.枚举常量 ...

  3. rocketmq-spring : 实战与源码解析一网打尽

    RocketMQ 是大家耳熟能详的消息队列,开源项目 rocketmq-spring 可以帮助开发者在 Spring Boot 项目中快速整合 RocketMQ. 这篇文章会介绍 Spring Boo ...

  4. flask+gunicorn+nginx部署pytorch/python应用

    1. 基于flask实现python服务Flask是一个使用 Python 编写的轻量级 Web 应用框架.其 WSGI 工具箱采用 Werkzeug ,模板引擎则使用 Jinja2 .Flask使用 ...

  5. Cesium案例(八) Terrain

    第一步正常建viewer,需要注意的是官网例子属性值比较老,最新版本的属性值有所差异,全copy官网会无法运行,提示函数未定义. 第一处差异 官网: 1 const viewer = new Cesi ...

  6. MySQL主从复制原理剖析与应用实践

    vivo 互联网服务器团队- Shang Yongxing MySQL Replication(主从复制)是指数据变化可以从一个MySQL Server被复制到另一个或多个MySQL Server上, ...

  7. day65:Linux:nginx代理&nginx负载均衡

    目录 1.nginx代理 2.nginx代理与配置 3.nginx负载均衡调度多web节点(静态页面) 4.nginx负载均衡调度多应用节点(blog) 5.nginx_proxy + web应用节点 ...

  8. 微服务为什么要用到 API 网关?

    本文介绍了 API 网关日志的价值,并以知名网关 Apache APISIX 为例,展示如何集成 API 网关日志. 作者程小兰,API7.ai 技术工程师,Apache APISIX Contrib ...

  9. 笔记:C++学习之旅---顺序容器

    笔记:C++学习之旅---顺序容器 STL = Standard Template Library   标准库模版 容器可以使用范围for输出或者迭代器进行输出 一个容器就是一些特定类型对象的集合.顺 ...

  10. vue路由的两种方式(路由传参)

    query和params区别 query类似 get, 跳转之后页面 url后面会拼接参数,类似?id=1, 非重要性的可以这样传, 密码之类还是用params刷新页面id还在 params类似 po ...