Is there a way to avoid automatically updating Rails timestamp fields?

Do this in a migration or in a rake task (or in the new database seeds if you’re on edge rails): ActiveRecord::Base.record_timestamps = false begin run_the_code_that_imports_the_data ensure ActiveRecord::Base.record_timestamps = true # don’t forget to enable it again! end You can safely set created_at and updated_at manually, Rails won’t complain. Note: This also works on individual … Read more

JavaScript timestamp to Python datetime conversion

Your current method is correct, dividing by 1000 is necessary because your JavaScript returns the timestamp in milliseconds, and datetime.datetime.fromtimestamp() expects a timestamp in seconds. To preserve the millisecond accuracy you can divide by 1000.0, so you are using float division instead of integer division: >>> dt = datetime.datetime.fromtimestamp(jsts/1000.0) >>> dt datetime.datetime(2012, 4, 23, 11, … Read more

How to make onEdit() trigger function apply to multiple sheets

For future readers, the code snippet in Paul’s question is derived from code on the Google Docs help forum, which includes a detailed line-by-line explanation. The function uses the variable sheetToWatch to identify one sheet (aka “tab”) that the onEdit() function cares about. That is validated by this comparison: || e.source.getActiveSheet().getName() !== sheetToWatch …and if … Read more

Timestamps for embedded system

If you have C++11 you can use the <chrono> and <ctime> library like this: #include <ctime> #include <string> #include <chrono> #include <sstream> #include <iomanip> #include <iostream> // use strftime to format time_t into a “date time” std::string date_time(std::time_t posix) { char buf[20]; // big enough for 2015-07-08 10:06:51\0 std::tm tp = *std::localtime(&posix); return {buf, std::strftime(buf, … Read more

Formatting timestamp in Java

Probably you’re looking at the String representation the Timestamp object gives in your database engine or its Java representation by printing it in the console using System.out.println or by another method. Note that which is really stored (in both Java side or in your database engine) is a number that represents the time since epoch … Read more