使用python或VB脚本将月/日/年转换为年

使用python或VB脚本将月/日/年转换为年,python,vbscript,Python,Vbscript,数据格式如下: 2014年1月5日,希望将该日期格式转换为单年整数短格式 将输入字符串的适当分割部分转换为数字: >> sDate = "05/01/2014" >> iYear = CInt(Split(sDate, "/")(2)) >> WScript.Echo TypeName(iYear), iYear >> Integer 2014 将输入字符串转换为区域设置上的日期依赖项,并使用Year函数: >> dtDate = C

数据格式如下: 2014年1月5日,希望将该日期格式转换为单年整数短格式

将输入字符串的适当分割部分转换为数字:

>> sDate = "05/01/2014"
>> iYear = CInt(Split(sDate, "/")(2))
>> WScript.Echo TypeName(iYear), iYear
>>
Integer 2014
将输入字符串转换为区域设置上的日期依赖项,并使用Year函数:

>> dtDate = CDate(sDate)
>> iYear = Year(dtDate)
>> WScript.Echo TypeName(iYear), iYear
>>
Integer 2014
Python 2.5,用于打印:

通过字符串/int conv c@false:

>>> sDate = "01/05/2014"
>>> iYear = int(sDate.split("/")[-1])
>>> print type(iYear), iYear
<type 'int'> 2014
通过日期时间:

>>> import datetime
>>> iYear = datetime.datetime.strptime('05/01/2014', '%m/%d/%Y').year
>>> print type(iYear), iYear
<type 'int'> 2014

你试过什么吗?尤其是在Python中?提示:ints.split“/”[-1]尚未尝试任何操作。我试着先搜索一下这个网站,但没有找到我想要的东西。我将尝试使用您的方法,感谢您的帮助并让您知道progressi使用了最后一个python scrip via datetime进行测试,它的工作原理与宣传的一样,谢谢