Answers for "days to milliseconds java"

0

java milliseconds to days hours minutes seconds

package com.roytuts.time;
import java.util.concurrent.TimeUnit;
public class MillisToDayHrMinSec {
	public static void main(String[] args) {
		final long milliseconds = 5478965412358l;
		final long dy = TimeUnit.MILLISECONDS.toDays(milliseconds);
		final long hr = TimeUnit.MILLISECONDS.toHours(milliseconds)
				- TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(milliseconds));
		final long min = TimeUnit.MILLISECONDS.toMinutes(milliseconds)
				- TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(milliseconds));
		final long sec = TimeUnit.MILLISECONDS.toSeconds(milliseconds)
				- TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milliseconds));
		final long ms = TimeUnit.MILLISECONDS.toMillis(milliseconds)
				- TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(milliseconds));
		System.out
				.println(String.format("%d Days %d Hours %d Minutes %d Seconds %d Milliseconds", dy, hr, min, sec, ms));
	}
}
Posted by: Guest on September-24-2020
0

date to milliseconds java

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

public class HelloWorld{

     public static void main(String []args){

		String myDate = "2020-02-26 03:57:35";
		LocalDateTime localDateTime = LocalDateTime.parse(myDate,
		    DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") );
		    
		    long millis = localDateTime
		    .atZone(ZoneId.of("America/Chicago")) //optional
		    .toInstant().toEpochMilli();
    
		System.out.println(millis);
     }
}
Posted by: Guest on January-06-2021

Code answers related to "days to milliseconds java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language