How to convert a unix timestamp (seconds since epoch) to Ruby DateTime?

Sorry, brief moment of synapse failure. Here’s the real answer. require ‘date’ Time.at(seconds_since_epoch_integer).to_datetime Brief example (this takes into account the current system timezone): $ date +%s 1318996912 $ irb ruby-1.9.2-p180 :001 > require ‘date’ => true ruby-1.9.2-p180 :002 > Time.at(1318996912).to_datetime => #<DateTime: 2011-10-18T23:01:52-05:00 (13261609807/5400,-5/24,2299161)> Further update (for UTC): ruby-1.9.2-p180 :003 > Time.at(1318996912).utc.to_datetime => #<DateTime: 2011-10-19T04:01:52+00:00 … Read more

Conversion of a datetime2 data type to a datetime data type results out-of-range value

Short Answer This can happen if you do not initialize a value to a DateTime field; the field does not accept NULL values, and it’s a value type, so the default value of the non-nullable DateTime type will be used. Setting the value fixed it for me! Long Answer The value of default(DateTime) is DateTime.MinValue … Read more

Can’t subtract offset-naive and offset-aware datetimes

have you tried to remove the timezone awareness? from http://pytz.sourceforge.net/ naive = dt.replace(tzinfo=None) may have to add time zone conversion as well. edit: Please be aware the age of this answer. An answer involving ADDing the timezone info instead of removing it in python 3 is below. https://stackoverflow.com/a/25662061/93380

How to change time in DateTime?

You can’t change a DateTime value – it’s immutable. However, you can change the variable to have a new value. The easiest way of doing that to change just the time is to create a TimeSpan with the relevant time, and use the DateTime.Date property: DateTime s = …; TimeSpan ts = new TimeSpan(10, 30, … Read more

How to parse/format dates with LocalDateTime? (Java 8)

Parsing date and time To create a LocalDateTime object from a string you can use the static LocalDateTime.parse() method. It takes a string and a DateTimeFormatter as parameter. The DateTimeFormatter is used to specify the date/time pattern. String str = “1986-04-08 12:30”; DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“yyyy-MM-dd HH:mm”); LocalDateTime dateTime = LocalDateTime.parse(str, formatter); Formatting date and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)