gettime

How Can I Tell if My struct tm Has Been Left in an Invalid State?

↘锁芯ラ 提交于 2019-11-28 08:46:09
问题 This is a question about invalid input, not invalid formatting. For example given the following code: tm bar; foo >> get_time(&bar, "%Y-%m-%d"); cout >> bar.tm_year >> bar.tm_mon >> bar.tm_mday >> endl; This is fine if I define: stringstream foo("2001-02-28 non-leap year"); And has a clear error if I have invalid format such as: stringstream foo("bad format 2001-02-28 non-leap year"); But I don't know how to detect if my input was invalid for example: stringstream foo("2001-02-30 non-leap

jQuery getTime function

点点圈 提交于 2019-11-27 11:08:00
问题 is it possible to create a jQuery function so that it gets current date and time? I've been looking around documentation but haven't found anything so far... 回答1: @nickf's correct. However, to be a little more precise: // if you try to print it, it will return something like: // Sat Mar 21 2009 20:13:07 GMT-0400 (Eastern Daylight Time) // This time comes from the user's machine. var myDate = new Date(); So if you want to display it as mm/dd/yyyy, you would do this: var displayDate = (myDate

Calculate time difference between two times javascript

假装没事ソ 提交于 2019-11-27 06:10:27
问题 i've looking around how to do this and i found a lot of examples with complicated code. Im using this: var time1 = new Date(); var time1ms= time1.getTime(time1); //i get the time in ms then i do this in other part of the code var time2 = new Date(); var time2ms= time2.getTime(time2); and finnally: var difference= time2ms-time1ms; var lapse=new Date(difference); label.text(lapse.getHours()+':'+lapse.getMinutes()+':'+lapse.getSeconds()); This works great, except for one issue, the hours it