Compare Date object with a TimeStamp in Java

tl;dr Use the modern java.time classes instead of those troublesome legacy date-time classes. myPreparedStatement.setObject( … , Instant.now() // Capture the current moment in UTC. ) Old Date-Time Classes Poorly Designed Put more bluntly, the java.sql.Timestamp/.Date/.Time classes are a hack, a bad hack. Like java.util.Date/.Calendar, they are the result of poor design choices. The java.sql types … Read more

Setting creation or change timestamps

For ext2/3 and possibly for ext4 you can do this with debugfs tool, assuming you want to change the ctime of file /tmp/foo which resides in disk /dev/sda1 we want to set ctime to 201001010101 which means 01 January 2010, time 01:01: Warning: Disk must be unmounted before this operation # Update ctime debugfs -w … Read more

How to group objects with timestamps properties by day, week, month?

All the solutions above are hefty, pure JS, vanilla solutions. If you’re okay to use a couple of libraries, then lodash and moment can be used together for a simple one liner: ES6 let groupedResults = _.groupBy(results, (result) => moment(result[‘Date’], ‘DD/MM/YYYY’).startOf(‘isoWeek’)); Older JS var groupedResults = _.groupBy(results, function (result) { return moment(result[‘Date’], ‘DD/MM/YYYY’).startOf(‘isoWeek’); }); This … Read more

Add Timestamp to Trace.WriteLine()

Via code You can configure the TraceOutputOptions flags enum. var listener = new ConsoleTraceListener() { TraceOutputOptions = TraceOptions.Timestamp | TraceOptions.Callstack }; Trace.Listeners.Add(listener); Trace.TraceInformation(“hello world”); This does not work for Write and WriteLine, you have use the TraceXXX methods. Via app.config This can also be configured in your App.config with a somewhat equivalent and using TraceSource: … Read more