You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2022/03/09 06:06:40 UTC
[GitHub] [incubator-kyuubi] yaooqinn commented on pull request #2068: Using separate date time formatter for each toTRowSet opeartion
yaooqinn commented on pull request #2068:
URL: https://github.com/apache/incubator-kyuubi/pull/2068#issuecomment-1062584708
How about?
```scala
class DateTimeFormatter {
private lazy val dateFormatter = {
createDateTimeFormatterBuilder().appendPattern("yyyy-MM-dd")
.toFormatter(Locale.US)
.withChronology(IsoChronology.INSTANCE)
}
private lazy val simpleDateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US)
private lazy val timestampFormatter: DateTimeFormatter = {
createDateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss")
.appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true)
.toFormatter(Locale.US)
.withChronology(IsoChronology.INSTANCE)
}
private lazy val simpleTimestampFormatter = {
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US)
}
private def createDateTimeFormatterBuilder(): DateTimeFormatterBuilder = {
new DateTimeFormatterBuilder().parseCaseInsensitive()
}
def formatDate(d: Date): String = {
simpleDateFormatter.format(d)
}
def formatLocalDate(d: LocalDate): String = {
dateFormatter.format(d)
}
def formatInstant(i: Instant): String = {
timestampFormatter.format(i)
}
def formatTimestamp(t: Timestamp): String = {
simpleTimestampFormatter.format(t)
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org