How can I 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

How to compare sqlite TIMESTAMP values

The issue is with the way you’ve inserted data into your table: the +0200 syntax doesn’t match any of SQLite’s time formats: YYYY-MM-DD YYYY-MM-DD HH:MM YYYY-MM-DD HH:MM:SS YYYY-MM-DD HH:MM:SS.SSS YYYY-MM-DDTHH:MM YYYY-MM-DDTHH:MM:SS YYYY-MM-DDTHH:MM:SS.SSS HH:MM HH:MM:SS HH:MM:SS.SSS now DDDDDDDDDD Changing it to use the SS.SSS format works correctly: sqlite> CREATE TABLE Foo (created_at TIMESTAMP); sqlite> INSERT INTO … Read more

Spark DataFrame TimestampType – how to get Year, Month, Day values from field?

Since Spark 1.5 you can use a number of date processing functions: pyspark.sql.functions.year pyspark.sql.functions.month pyspark.sql.functions.dayofmonth pyspark.sql.functions.dayofweek pyspark.sql.functions.dayofyear pyspark.sql.functions.weekofyear import datetime from pyspark.sql.functions import year, month, dayofmonth elevDF = sc.parallelize([ (datetime.datetime(1984, 1, 1, 0, 0), 1, 638.55), (datetime.datetime(1984, 1, 1, 0, 0), 2, 638.55), (datetime.datetime(1984, 1, 1, 0, 0), 3, 638.55), (datetime.datetime(1984, 1, 1, 0, 0), … Read more

Python pandas convert datetime to timestamp effectively through dt accessor

I think you need convert first to numpy array by values and cast to int64 – output is in ns, so need divide by 10 ** 9: df[‘ts’] = df.datetime.values.astype(np.int64) // 10 ** 9 print (df) datetime ts 0 2016-01-01 00:00:01 1451606401 1 2016-01-01 01:00:01 1451610001 2 2016-01-01 02:00:01 1451613601 3 2016-01-01 03:00:01 1451617201 4 … Read more

Convert a Date (absolute time) to be sent/received across the network as Data in Swift?

You can send your Date converting it to Data (8-bytes floating point) and back to Date as follow: extension Numeric { var data: Data { var source = self return .init(bytes: &source, count: MemoryLayout<Self>.size) } init<D: DataProtocol>(_ data: D) { var value: Self = .zero let size = withUnsafeMutableBytes(of: &value, { data.copyBytes(to: $0)} ) assert(size … Read more

How to convert HH:mm:ss.SSS to milliseconds?

You can use SimpleDateFormat to do it. You just have to know 2 things. All dates are internally represented in UTC .getTime() returns the number of milliseconds since 1970-01-01 00:00:00 UTC. package se.wederbrand.milliseconds; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static void main(String[] args) throws Exception { SimpleDateFormat sdf = new … Read more