This question already has answers here:
QDate - wrong year
(3 answers)
Closed 7 years ago.
i'm trying to use QDateTime for one of my project. But everything is going wrong when i use QDateTime::currentTime().msecsTo() ....
QString FORMAT = "d/MM/yy hh:mm:ss";
QDateTime at = QDateTime::fromString("30/06/15 12:00:00", FORMAT);
qDebug() << QDateTime::currentDateTime().msecsTo(at); //Current DateTIme : 30/06/15 11:51:00 OUTPUT : -3155755905986
And the out put gives me : -3155755905986
Which doesn't make any sens ...
Any idea ?
Thank you.
Actually everything is ok for qt this value is 100 years earlier - 30/06/1915
https://www.unitjuggler.com/convert-time-from-ms-to-yr-365.html?val=3155756569078
QDate - wrong year
I suggest using format "dd/MM/yyyy hh:mm:ss"
Qt doc says if the other datetime is earlier than this datetime, the value returned is negative. I think it is expected behaviour.
Related
This question already has answers here:
How to convert a List<T?> to List<T> in null safe Dart?
(2 answers)
type 'List<Widget?>' is not a subtype of type 'List<Widget>' in type cast
(3 answers)
Closed 1 year ago.
I have a List of optional DateTimes. So the List can actually have null values inside. But now I need to remove all these null-values, to get a List<DateTime, instead of a List<DateTime?>. How is that possible?
I tried it like this:
List<DateTime> timesOfDayNotNull = timesOfDay.where((time) => time != null).toList();
But this is giving me:
A value of type 'List<DateTime?>' can't be assigned to a variable of type 'List'.
What am I missing here? Any help is appreciated!
This question already has answers here:
How to convert a timezone aware string to datetime in Python without dateutil?
(7 answers)
Closed 3 years ago.
I'm using Django and Python 3.7. I'm parsing some strings into dates using this logic ...
created_on = datetime.strptime(created_on_txt, '%Y-%m-%dT%H:%M:%S+00:00')
print(created_on.tzinfo)
How do I incorporate the fact that the time zone I want to be interpreted for the string shoudl be UTC? When I print out the ".tzinfo," it reads "None." An example of something I'm parsing is
2019-04-08T17:03:00+00:00
Python 3.7, lucky you:
created_on = datetime.fromisoformat('2019-04-08T17:03:00+00:00')
created_on.tzinfo
>>> datetime.timezone.utc
If you insist on using strptime():
created_on = datetime.strptime('2019-04-08T17:03:00+00:00', '%Y-%m-%dT%H:%M:%S%z')
created_on.tzinfo
>>> datetime.timezone.utc
This uses the %z directive.
This question already has answers here:
Matching a Forward Slash with a regex
(9 answers)
Closed 3 years ago.
I have lot of Data in Mongo DB, I wanted to query based on a String value and that value contains a url
"url" : "http://some-host/api/name/service/list/1234/xyz"
I got records count when executed the below query
db.mycollection.find({url:"http://some-host/api/name/service/list/1234/xyz"}).count()
I want to get all the records which match with
some-host/api/name/service/list/
I tried using below saamples
db.mycollection.find({url:"some-host/api/name/service/list/"}).count()
Got zero records
db.mycollection.find({url:/.*"some-host/api/name/service/list/".*/}).count()
Got error
db.mycollection.find({"url":/.*"some-host/api/name/service/list/".*/}).count()
Got error
db.mycollection.find({"url":/.*some-host/api/name/service/list/.*/}).count()
Got Error
db.mycollection.find({"url":/.*some-host//api//name//service//list//.*/}).count()
Got ...
...
Then no response
Did you try with something like this:
db.mycollection.find({'url': {'$regex': 'sometext'}})
Please check also here
This question already has answers here:
Ternary operation in CoffeeScript
(8 answers)
Closed 6 years ago.
I’m using Rails 4.2.3. In my coffee script, I have
console.log(hours)
hours = (hours < 10 ? "0" + hours : hours)
console.log(hours)
but I’m getting some strange results. In the first line, console.log is printing out “14” (a number), but in the next console.log, it prints out “false”. I don’t understand why this is happening. It should remain “14”. What do I need to do to fix this?
try :
hours = (hours < 10 ? "0" + hours.to_s : hours)
I have some code that reads a datetime from a sqlite database, the datetime is returned as a string. when I try to convert it to a date using QDateTime::FromString it returns an invalid date. Below is the time as returned from the database and conversion.
Why is this failing to parse?
// -this is the value returned from the DB currentServerTime=2012-01-17 19:20:27.0
QString format("yyyy/MM/dd hh:mm:ss");
QString qCurrentServerTime(currentServerTime);
now = QDateTime::fromString(qCurrentServerTime, format);
No expert in QT, but if QDateTime::fromString() works as one would (reasonably) expect and according to this, you're not using the correct pattern.
You indicate the string read from the sqllite database is like "2012-01-17 19:20:27.0", then your format should be like yyyy-MM-dd HH:mm:ss.z.
In detail:
Your separator should by '-' not '/' (as you show in the example)
The time seems to be in 24 hours format (19 -> 7 p.m.) (so use HH instead of hh)
You have one digit for milliseconds, so add .z.