import datetime
import time

string转datetime
            str = '2012-11-19'
            date_time = datetime.datetime.strptime(str,'%Y-%m-%d')
            date_time
datetime.datetime(,,,,)

datetime转string
            date_time.strftime('%Y-%m-%d')
'2012-11-19'

datetime转时间戳
            time_time = time.mktime(date_time.timetuple())
            time_time
1353254400.0

时间戳转string
            time.strftime('%Y-%m-%d',time.localtime(time_time))
'2012-11-19'

date转datetime
            date = datetime.date.today()
            date
            datetime.date(,,)
            datetime.datetime.strptime(str(date),'%Y-%m-%d') #将date转换为str,在由str转换为datetime
            datetime.datetime(,,,,)

date、datetime、string的相互转换的更多相关文章

  1. iOS中date和string的相互转换

    必须知道的内容 G: 公元时代,例如AD公元     yy: 年的后2位     yyyy: 完整年     MM: 月,显示为1-12     MMM: 月,显示为英文月份简写,如 Jan      ...

  2. Java中Date与String的相互转换

    我们在注册网站的时候,往往需要填写个人信息,如姓名,年龄,出生日期等,在页面上的出生日期的值传递到后台的时候是一个字符串,而我们存入数据库的时候确需要一个日期类型,反过来,在页面上显示的时候,需要从数 ...

  3. Date与String的相互转换

    构造函数 日期:new Date();//获取当前日期,精确到毫秒. 日期:new Date(long date);//即1970 年 1 月 1 日 00:00:00 GMT(Greenwich M ...

  4. python中date、datetime、string的相互转换

    import datetime import time string转datetime str = '2012-11-19' date_time = datetime.datetime.strptim ...

  5. 异常-----Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string.\u003Cformat> or ?string(format) built-

    1.错误描述 五月 27, 2014 12:07:05 上午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...

  6. mybatis的判定时间字段问题 java.lang.IllegalArgumentException: invalid comparison: cn.hutool.core.date.DateTime and java.lang.String

    今天听组员说: mybatis在3.30版本及以上判定时间时 <if test="date_time != null and date_time != '' "> da ...

  7. Date和String类型的相互转换

    String转Date: SimpleDateFormat bartDateFormat = new SimpleDateFormat("MM-dd-yyyy"); String ...

  8. Android:Date、String、Long三种日期类型之间的相互转换

    源地址:http://blog.csdn.net/wangyanguiyiyang date类型转换为String类型: // formatType格式为yyyy-MM-dd HH:mm:ss//yy ...

  9. java中XMLGregorianCalendar类型和Date类型之间的相互转换

    import java.text.SimpleDateFormat;import java.util.Date;import java.util.GregorianCalendar;import ja ...

随机推荐

  1. MVC中AuthorizeAttribute用法并实现权限控制

    1.创建一个类(用来检查用户是否登录和用户权限)代码如下: public class AuthorizeFilterAttribute: AuthorizeAttribute    { //Autho ...

  2. Linux下Apache服务器并发优化

     Linux/UnixLinux系统下Apache 并发数的优化 Apache Http服务器采用prefork或者是worker两种并发控制模式. preforkMPM 使用多个子进程,每个子进程只 ...

  3. Java疯狂讲义

  4. Zookper

    http://blog.csdn.net/yangbutao/article/details/11669609 http://www.oschina.net/code/snippet_255033_2 ...

  5. android linearlayout 把控件view置底部(放在页面最下方)

    <LinearLayout android:id="@+id/recLayout" android:layout_width="fill_parent" ...

  6. Linux学习:curl 与 wget命令

    curl和wget命令都是Linux下的工具,可以用来下载文件. 一.wget 例1: wget http://www.minjieren.com/wordpress-3.1-zh_CN.zip 下载 ...

  7. Mylyn

    Mylyn(旧称Mylar)是eclipse的一个插件,用于将任务管理和上下文管理无缝集成到Eclipse中.1. 安装 下载相应的Mylyn zip包,解压缩开就是两个文件夹:features和pl ...

  8. Trie树:应用于统计和排序

    Trie树:应用于统计和排序 1. 什么是trie树 1.Trie树 (特例结构树)       Trie树,又称单词查找树.字典树,是一种树形结构,是一种哈希树的变种,是一种用于快速检索的多叉树结构 ...

  9. 质因数分解的rho以及miller-rabin

    一.前言 质因数分解,是一个在算法竞赛里老生常谈的经典问题.我们在解决许多问题的时候需要用到质因数分解来辅助运算,而且质因数分解牵扯到许许多多经典高效的算法,例如miller-rabin判断素数算法, ...

  10. large-scale analysis of malware downloaders

    http://www.christian-rossow.de/publications/downloaders-dimva12.pdf