Parsing String Dates and Changing locale

from Spotfire.Dxp.Data.DataType import Date

#this will parse ok
print Date.Formatter.FormatString
print Date.Formatter.Parse("21Jun2000")
dt = Date.Formatter.Parse("7/28/2014")

#this line will crash
#print Date.Formatter.Parse("28/7/2014") 

#change the correct culture
from System.Globalization import CultureInfo
parser = Date.CreateCultureSpecificFormatter(CultureInfo("es-MX"))

#now is safe to parse
print parser.Parse("28/7/2014")
print parser.Parse("27-10-2014")
print parser.Parse("DEC31-2014")

#current date and time
from System import DateTime
now = DateTime.Now
today = DateTime.Today

No comments: