我需要将日期字符串“28/01/2018”(dd / mm / yyyy)转换为qml中的Date()。
我试过这个:
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains four space-separated integers N, M, X and K.
The second line contains a single string S.
for t in xrange(int(raw_input())):
n, m, x, k = map(int, raw_input().split())
s = raw_input()
even = m/2
odd = m - even
e, o = 0, 0
work, worked = 0, 0
for i in s:
if i == 'E':
e += 1
else:
o += 1
for k in xrange(even):
if e > 0 and e >= x:
worked += x
e -= x
elif e > 0 and e < x:
worked += e
e -= e
for j in xrange(odd):
if o > 0 and o >= x:
work += x
o -= x
elif o > 0 and o < x:
work += o
o -= o
if work + worked == n:
print 'yes'
else:
print 'no'
还看到了这个: conversione from string ,但我的问题是我继续收到“NaN”或“无效日期”,如何从qml中的字符串中获取Date()?
由于
答案 0 :(得分:1)
传递给 var dateBoard = "01/31/2018"
var someDateTest = Date.fromLocaleString(Qt.locale(), dateBoard, "dd/MM/yyyy")
var test = someDateTest.getDate() //nan
的字符串必须是预期的格式。试试这段代码:
dateBoard
由于fromLocaleString
中的字符串代表 MM / dd / yyyy 格式的日期,getDate
将返回无效日期和nan
{{1}因此。
如果dateBoard
为空字符串,为空或未定义,则同样适用。