C# DateTime: What “date” to use when I’m using just the “time”?
what about DateTime.MinValue?
what about DateTime.MinValue?
You can use the crate chrono to achieve the same result: extern crate chrono; use chrono::Local; fn main() { let date = Local::now(); println!(“{}”, date.format(“%Y-%m-%d][%H:%M:%S”)); } Edit: The time crate is not deprecated: it is unmaintained. Besides, it is not possible to format a time using only the standard library.
NSDate *localDate = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; dateFormatter.dateFormat = @”MM/dd/yy”; NSString *dateString = [dateFormatter stringFromDate: localDate]; NSDateFormatter *timeFormatter = [[NSDateFormatter alloc]init]; timeFormatter.dateFormat = @”HH:mm:ss”; NSString *dateString = [timeFormatter stringFromDate: localDate]; There are many many different ways to represent the date and time so check NSDateFormatter for more info.
To round up to the nearest 30 minutes: #!/usr/bin/env python3 from datetime import datetime, timedelta def ceil_dt(dt, delta): return dt + (datetime.min – dt) % delta now = datetime.now() print(now) print(ceil_dt(now, timedelta(minutes=30))) The formula is suggested by @Mark Dickinson (for a different question). Output 2015-09-22 19:08:34.839915 2015-09-22 19:30:00 Note: if the input is timezone-aware datetime … Read more
SELECT DATE(timestamp) Date, COUNT(DISTINCT ipNum) totalCOunt FROM tableName GROUP BY DATE(timestamp) SQLFiddle Demo
You can use mock library in your tests. import time from mock import patch class MyTestCase(…): @patch(‘time.sleep’, return_value=None) def my_test(self, patched_time_sleep): time.sleep(666) # Should be instant
The problem is that parsedate will ignore the offset. Do this instead: from email.utils import parsedate_tz print parsedate_tz(‘Fri, 15 May 2009 17:58:28 +0700’)
Create a new date using the current day/month/year, and get the difference. var now = new Date(), then = new Date( now.getFullYear(), now.getMonth(), now.getDate(), 0,0,0), diff = now.getTime() – then.getTime(); // difference in milliseconds
you could always do #do some stuff print ‘tasks done, now sleeping for 10 seconds’ for i in xrange(10,0,-1): time.sleep(1) print i This snippet has the slightly annoying feature that each number gets printed out on a newline. To avoid this, you can import sys import time for i in xrange(10,0,-1): sys.stdout.write(str(i)+’ ‘) sys.stdout.flush() time.sleep(1)
If you’re using moment.js you can simply call… moment.duration(‘PT15M33S’).asMilliseconds(); = 933000 ms EDIT 2021: While this works, and still gets upvotes, I wouldn’t advise including moment.js just for this. I’d recommend using a regex answer like @redgetan’s