Convert LocalDateTime to Milliseconds - Java java.time

Java examples for java.time:LocalDateTime

Description

Convert LocalDateTime to Milliseconds

Demo Code

/*//w  w  w . ja va 2 s.c om
 * Copyright 2014-2015 Christian Raue
 * MIT License http://opensource.org/licenses/mit-license.php
 */
//package com.java2s;

import java.time.LocalDateTime;

import java.time.temporal.ChronoUnit;

public class Main {
    /**
     * @param dateTime Datum/Zeit-Wert
     * @return UTC-basierter Datum/Zeit-Wert in ms
     */
    public static long getLocalDateTimeInMillis(final LocalDateTime dateTime) {
        return LocalDateTime.of(1970, 1, 1, 0, 0, 0).until(dateTime,
                ChronoUnit.MILLIS);
    }
}

Related Tutorials