Java SQL Time serialize(LocalDateTime date)

Here you can find the source of serialize(LocalDateTime date)

Description

serialize

License

Apache License

Declaration

public static String serialize(LocalDateTime date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.time.LocalDateTime;
import java.time.ZoneId;

import java.time.format.DateTimeFormatter;
import java.util.Date;

public class Main {
    private static final DateTimeFormatter ISO_FORMAT = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
    public static final ZoneId UTC = ZoneId.of("UTC");

    public static String serialize(LocalDateTime date) {
        return date.format(ISO_FORMAT);
    }//  w w  w . ja  va2  s  . c  o m

    public static String serialize(Date date) {
        return serialize(fromUtilDate(date));
    }

    public static LocalDateTime fromUtilDate(Date date) {
        if (date.getClass() == Date.class) {
            return LocalDateTime.ofInstant(date.toInstant(), UTC);
        }
        return fromUtilDate(new Date(date.getTime())); //hack for old java.sql.Date
    }
}

Related

  1. resetDayTime(Time date)
  2. resetNetworkTimeout(Connection rawConnection, Executor executor, int oldTimeout)
  3. roundDatetimeValue(Object value)
  4. roundSmallDateTimeValue(Object value)
  5. saveGameScores(String gameName, String player1, String player2, String player3, String player4, short score1, short score2, short score3, short score4, java.util.Date startTime)
  6. serializeSqlTime(Time time)
  7. setTime(PreparedStatement statement, int index, Date value)
  8. sqlDateTimeAdd(java.util.Date date, long milliseconds)
  9. sqlTime()