{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "d548ba1c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.4.8" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "spark.version" ] }, { "cell_type": "markdown", "id": "acb5ca7e", "metadata": {}, "source": [ "## string to java.sql.Timestamp" ] }, { "cell_type": "markdown", "id": "781adda2", "metadata": {}, "source": [ "just use `Timestamp.valueOf`" ] }, { "cell_type": "code", "execution_count": 5, "id": "439887f0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ts = 2022-05-12 12:00:00.123\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "2022-05-12 12:00:00.123" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import java.sql.Timestamp\n", "\n", "val ts = Timestamp.valueOf(\"2022-05-12 12:00:00.123\")" ] }, { "cell_type": "markdown", "id": "ef3e978b", "metadata": {}, "source": [ "## time.Instant to sql.Timestamp" ] }, { "cell_type": "code", "execution_count": 8, "id": "6ebaa46b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "instantObj = 2022-06-13T04:37:01.378Z\n", "ts = 2022-06-13 01:37:01.378\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "2022-06-13 01:37:01.378" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import java.time.Instant\n", "import java.sql.Timestamp\n", "\n", "val instantObj = Instant.now()\n", "\n", "val ts = Timestamp.from(instantObj)" ] } ], "metadata": { "kernelspec": { "display_name": "Apache Toree - Scala", "language": "scala", "name": "apache_toree_scala" }, "language_info": { "codemirror_mode": "text/x-scala", "file_extension": ".scala", "mimetype": "text/x-scala", "name": "scala", "pygments_lexer": "scala", "version": "2.11.12" } }, "nbformat": 4, "nbformat_minor": 5 }