Set time zone offset in Ruby

Set the TZ environment variable… $ ruby -e ‘puts Time.now’ Sat Jan 15 20:49:10 -0800 2011 $ TZ=UTC ruby -e ‘puts Time.now’ Sun Jan 16 04:49:20 +0000 2011 Ruby gets the time zone information from the host’s operating system. Most directly, it uses a C library API specified by C99 and Posix. The implementation of … Read more

How to parse non standard time format from json

That’s a case when you need to implement custom marshal and unmarshal functions. UnmarshalJSON(b []byte) error { … } MarshalJSON() ([]byte, error) { … } By following the example in the Golang documentation of json package you get something like: // First create a type alias type JsonBirthDate time.Time // Add that to your struct … Read more

Setting timezone globally in golang

You can achieve what you want from inside your app using os.Setenv(“TZ”, “Africa/Cairo”), what matters is that you must call this before any other package uses anything from the time package. How to ensure that? Create a package that does nothing else except sets the timezone (later you may add other things to it, but … Read more

Adding time stamp to log file in bash script

Note you are outputting to Debug.log, while you should indicate the full path of that file: echo “Time: $(date)” >> /path/to/Debug.log. In general, whenever you want to add timestamp to a log file, you can use: echo “Time: $(date). Some error info.” >> /path/to/your/file.log date will expand to something like Fri Sep 9 12:18:02 CEST … Read more

How to get the difference between two points in time in milliseconds

std::chrono::duration has two template parameters, the second being exactly the unit of measure. You can invoke std::chrono::duration_cast to cast from one duration type to another. Also, there is a predefined duration type for milliseconds: std::chrono::milliseconds. Composing this together: auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(foo – now); To get the actual number of milliseconds, use duration::count: auto ms … Read more

am/pm time to 24 hour format

Just convert it to a date using NSDateFormatter and the “h:mm a” format and convert it back to a string using the “HH:mm” format. Check out this date formatting guide to familiarize yourself with this material. let dateAsString = “6:35 PM” let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = “h:mm a” dateFormatter.locale = Locale(identifier: “en_US_POSIX”) // fixes … Read more

How do I get the current time in Python?

Use datetime: >>> import datetime >>> now = datetime.datetime.now() >>> now datetime.datetime(2009, 1, 6, 15, 8, 24, 78915) >>> print(now) 2009-01-06 15:08:24.789150 For just the clock time without the date: >>> now.time() datetime.time(15, 8, 24, 78915) >>> print(now.time()) 15:08:24.789150 To save typing, you can import the datetime object from the datetime module: >>> from datetime … Read more

How to store only time; not date and time?

You could try the INTERVAL DAY TO SECOND data type but it won’t save you any disk space … it is very suitable for this purpose though. create table t1 (time_of_day interval day (0) to second(0)); insert into t1 values (TO_DSINTERVAL(‘0 23:59:59’)); select date ‘2009-05-13’+time_of_day from t1; 11 bytes though.

tech