How do I deserialize timestamps that are in seconds with Jackson?

I wrote a custom deserializer to handle timestamps in seconds (Groovy syntax). class UnixTimestampDeserializer extends JsonDeserializer<DateTime> { Logger logger = LoggerFactory.getLogger(UnixTimestampDeserializer.class) @Override DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String timestamp = jp.getText().trim() try { return new DateTime(Long.valueOf(timestamp + ‘000’)) } catch (NumberFormatException e) { logger.warn(‘Unable to deserialize timestamp: ‘ + timestamp, e) … Read more

Parsing unix time in C#

Simplest way is probably to use something like: private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); … public static DateTime UnixTimeToDateTime(string text) { double seconds = double.Parse(text, CultureInfo.InvariantCulture); return Epoch.AddSeconds(seconds); } Three things to note: If your strings are definitely of the form “x.y” rather than “x,y” you should … Read more

How to get Unix timestamp in php based on timezone

The answer provided by Volkerk (that says timestamps are meant to be always UTC based) is correct, but if you really need a workaround (to make timezone based timestamps) look at my example. <?php //default timezone $date = new DateTime(null); echo ‘Default timezone: ‘.$date->getTimestamp().'<br />’.”\r\n”; //America/New_York $date = new DateTime(null, new DateTimeZone(‘America/New_York’)); echo ‘America/New_York: ‘.$date->getTimestamp().'<br … Read more

How to convert a String to long in javascript?

JavaScript has a Number type which is a 64 bit floating point number*. If you’re looking to convert a string to a number, use either parseInt or parseFloat. If using parseInt, I’d recommend always passing the radix too. use the Unary + operator e.g. +”123456″ use the Number constructor e.g. var n = Number(“12343”) *there … Read more