We can get datetime using qmake _DATE_ which outputs
Sat Mar 12 17:29:00 2022
Can we format this output?
By using QDateTime by passing the value of DATE (in fromString), you may be able to format the output the way you want, by using toString.
You can try things like this :
toString("ddd MMMM d hh:mm:ss yy"); //Sat Mar 12 17:29:00 2022
Related
I have a process where I need to to match UTC datetime and EDT datetime.
As you know, EDT can be changed between 4/5 hours from UTC.
How can I define one datetime to be in UTC and another to be in EDT and match the two?
Something like (datetime_A is my EDT timestamp, and datetime_B is my UTC):
Where CAST((datetime_A as EDT) to UTC)=datetime_B
Thanks!
I have to convert QString to QDateTime by QDateTime::fromString method. I have QString object which contains "Wed, 13 Jun 2018 12:52". But when I use it QDateTime::fromString returns invalid object and I don't knew why. I use "ddd, MM-MMM-yyyy HH:MM" format. Could anyone tell me what I doing wrong?
My code:
QString tempDate; //Wed, 13 Jun 2018 12:52
QDateTime::fromString(tempDate, "ddd, MM-MMM-yyyy HH:MM"); //returns invalid obj
Your QDateTime format does not correspond to your input string.
Wed, 13 Jun 2018 12:52 should be matched with ddd, dd MMM yyyy HH:mm.
See QDateTime::fromString.
Also, make sure you're using the correct locale when doing the conversion, as ddd and MMM are localized. Either change the local with QLocale::setDefault, or with QLocale::toDateTime:
QLocale(QLocale::English).toDateTime(tempDate, "ddd, dd MMM yyyy HH:mm");
QDateTime startTime = QDateTime::fromString (QString("1970-07-18T00:00:00"), Qt::ISODate);
I'm trying to take a date, for example Aug 22, 2017 02:00 PM EDT
and get the month, day, year from it.
month = re.findall(r'', date)[0]
day = re.findall(r'', date)[0]
year = re.findall(r'', date)[0]
I've started with something like this:
(.*)(?<=[a-zA-Z]{3}\s)
for the month. Is there a better way to do this?
You need to first convert to datetime and then extract the needed values like this (reusing the example):
from datetime import datetime
datetime_object = datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p')
print(datetime_object.year, datetime_object.month, datetime_object.day)
From what I can see you probably won't need to specify the format but pass the string directly to the datetime.strptime function.
I am working on a project using Ruby 2.2 and Rails 4 and sqlite database in which time difference is wrongly calculated.
I have used TimeDifference method for that purpose.
In my database there is a table MachineAttendance.
InTime is stored as Tue, 12 Feb 2017 20:30:00 UTC +00:00
OutTime is stored as Tue, 12 Feb 2017 05:30:00 UTC +00:00
#c1.in_time.strftime("%I:%M %p")
"08:30 PM"
#c1.out_time.strftime("%I:%M %p")
"05:30 AM"
And my method is
time_diff=TimeDifference.between(#c1.in_time.strftime('%H:%M:%S'), #c1.out_time.strftime('%H:%M:%S')).in_hours.to_f
its giving 15.0 hrs which is wrong
as it should be 9.0 hrs.
will anyone let me know how may i get correct difference.....thanks :)
You can try below its work for me
Time.at((#c1.out_time-#c1.in_time).round.abs).utc.strftime "%H:%M"
It will return time like "09:00"
I have strings in the following format "2013-02-20T17:24:33Z" and "Mon Feb 25 02:42:27 +0000 2013".
Is there a quick way to convert these into date time format so that they can be tested for equality and/or sorted.
clj-time does allow me to this format (date-time 1986 10 14 4 3 27 456). However to achieve this I will have to parse the two above strings. The above strings being standard formats, is there a way to directly convert them into date time objects?
Thanks,
Murtaza
clj-time has standard formatters defined, see clj-time.format/show-formatters, but your second format is not a 'standard' format as far as clj-time is concerned (although it does look suspiciously close to rfc822). You can create a custom formatter tho...
(use 'clj-time.format)
(parse (formatters :date-time-no-ms) "2013-02-20T17:24:33Z")
#<DateTime 2013-02-20T17:24:33.000Z>
(parse (formatter "E MMM dd hh:mm:ss Z YYYY") "Mon Feb 25 02:42:27 +0000 2013" )
#<DateTime 2013-02-25T02:42:27.000Z>
(show-formatters)
:basic-date 20130228
:basic-date-time 20130228T114047.213Z
:basic-date-time-no-ms 20130228T114047Z
:basic-ordinal-date 2013059
:basic-ordinal-date-time 2013059T114047.213Z
:basic-ordinal-date-time-no-ms 2013059T114047Z
:basic-t-time T114047.213Z
:basic-t-time-no-ms T114047Z
:basic-time 114047.213Z
:basic-time-no-ms 114047Z
:basic-week-date 2013W094
:basic-week-date-time 2013W094T114047.213Z
:basic-week-date-time-no-ms 2013W094T114047Z
:date 2013-02-28
:date-hour 2013-02-28T11
:date-hour-minute 2013-02-28T11:40
:date-hour-minute-second 2013-02-28T11:40:47
:date-hour-minute-second-fraction 2013-02-28T11:40:47.213
:date-hour-minute-second-ms 2013-02-28T11:40:47.213
:date-time 2013-02-28T11:40:47.213Z
:date-time-no-ms 2013-02-28T11:40:47Z
:hour 11
:hour-minute 11:40
:hour-minute-second 11:40:47
:hour-minute-second-fraction 11:40:47.213
:hour-minute-second-ms 11:40:47.213
:ordinal-date 2013-059
:ordinal-date-time 2013-059T11:40:47.213Z
:ordinal-date-time-no-ms 2013-059T11:40:47Z
:rfc822 Thu, 28 Feb 2013 11:40:47 +0000
:t-time T11:40:47.213Z
:t-time-no-ms T11:40:47Z
:time 11:40:47.213Z
:time-no-ms 11:40:47Z
:week-date 2013-W09-4
:week-date-time 2013-W09-4T11:40:47.213Z
:week-date-time-no-ms 2013-W09-4T11:40:47Z
:weekyear 2013
:weekyear-week 2013-W09
:weekyear-week-day 2013-W09-4
:year 2013
:year-month 2013-02
:year-month-day 2013-02-28
Use SimpleDateFormat.
(let [input "Mon Feb 25 02:42:27 +0000 2013"
fmt (java.text.SimpleDateFormat. "EEE MMM dd HH:mm:ss zzz yyyy")]
(.parse fmt input))
Remember that parsing months' and weekdays' names requires appropriately set locale.
As a side note, the first date format in your question is ISO 8601.