How to convert date string to timestamp in Kotlin?
use this to convert the date string to UNIX timestamp val date = SimpleDateFormat(“dd-MM-yyyy”).parse(“14-02-2018”) println(date.time)
use this to convert the date string to UNIX timestamp val date = SimpleDateFormat(“dd-MM-yyyy”).parse(“14-02-2018”) println(date.time)
“Unix timestamp” means seconds since the epoch in most situations rather than milliseconds… be careful! However, things like Java use “milliseconds since the epoch” which may be what you actually care about – despite the tool you showed. It really depends on what you need. Additionally, you shouldn’t be doing anything with local time. Stick … Read more
I know another answer was accepted a while ago, but this question appears high on Google’s search results, so I will add another answer. If you are working at the template level, you can use the U parameter to the date filter, e.g.: {{ mydate|date:”U” }} Note that it will be based upon the TIMEZONE … Read more
I strongly advise you to use Moment Date lib when working with dates in js. It’s really light and awesome. var timeStamp = ( moment(‘2009-07-15 00:00:00’).unix() )*1000
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
The timestamp is used for allowing the server to optimize their storage of nonces. Basically, consider the read nonce to be the combination of the timestamp and random string. But by having a separate timestamp component, the server can implement a time-based restriction using a short window (say, 15 minutes) and limit the amount of … Read more
Use Time.at. Time.at(1335437221) # => 2012-04-26 12:47:01 +0200
If you convert the maximum timestamp values with x digits in millis you get something like this: 9999999999999 (13 digits) means Sat Nov 20 2286 17:46:39 UTC 999999999999 (12 digits) means Sun Sep 09 2001 01:46:39 UTC 99999999999 (11 digits) means Sat Mar 03 1973 09:46:39 UTC Can your timestamps be older than 2001? If … Read more
A unix time stamp is defined as the number of seconds since January 1, 1970 UTC, except not counting all the seconds. This is somewhat ridiculous and one has to wonder what the point of it is, so I agree that this is a silly question. Anyway, lets look at some platform documentation for time_t … Read more