Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.time.Instant;
import java.util.Date;

public class Main {

    public static void main(String[] args) {
        System.out.println(roundTo30Minutes(new Date()));
    }

    public static Date roundTo30Minutes(final Date from) {
        long t = from.getTime();
        t = t - (t % (1000 * 60 * 30));
        t += (1000 * 60 * 30);
        return Date.from(Instant.ofEpochMilli(t));
    }
}