php语言转python,python各种语言间时间的转化实现代码

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace MyTest

{

class Program

{

static void DateTimeTest()

{

DateTime dt2 = DateTime.Now;

Console.WriteLine(dt2.Ticks);

Console.WriteLine(dt2.ToString("MM/dd/yyyy hh:mm:ss"));

}

static DateTime? ConvertPerlTimeToDateTime(string perltime)

{

DateTime? dt = null;

//perl time variable : seconds from 1970.01.01 00:00:00

string sdt = perltime;

long ldt = 0;

if (long.TryParse(sdt, out ldt))

{

long ldt2 = new DateTime(1970, 1, 1).Ticks + ldt * 1000 * 1000 * 10;

dt = new DateTime(ldt2, DateTimeKind.Local);

Console.WriteLine(dt.Value.ToString("MM/dd/yyyy hh:mm:ss"));

}

return dt;

}

static void Main(string[] args)

{

DateTimeTest();

ConvertPerlTimeToDateTime("1309423883");

//634462479788396720

//07/14/2011 01:46:18

//06/30/2011 08:51:23

}

}

}

四 python

python的perl相似,time也是从1970年1月1日开始的秒数。

import time

ISOTIMEFORMAT='%Y-%m-%d %X'

# seconds from 1970.01.01 00:00:00

t = time.time()

print (t)

print time.strftime(ISOTIMEFORMAT,time.localtime(t))

#1310623143.12

#2011-07-14 13:59:03

(year,mon,day,hour,min,sec,wday,yday,isdst) = time.localtime()

print (year)

print (time.strftime(ISOTIMEFORMAT, time.localtime()))

#2011

#2011-07-14 13:59:03

相关标签:时间 转化

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

相关文章

相关视频

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值