Get date-time in seconds from current date

get current time in seconds javascript
javascript get current time in milliseconds
epoch time
javascript get current timestamp
get time from date javascript
javascript timestamp to date
time get seconds
get current time in seconds python

Need to get date-time in seconds from current date. Want to add 2 days from current date-time and get value of 7 PM of result day.

I.E. Current date-time is 1 January, 7:05 PM OR 6:55 PM, I should get value of 3 January, 7:00 PM in seconds.

P.S. - Can't use JODA Time & Java 8.

Did you try ThreeTenABP by Jake Wharton? https://github.com/JakeWharton/ThreeTenABP. You can use it also for android versions before api 26 (required for the new java.time.instant) and it has all the functionalities of the Java 8 api.

I would do:

LocalDate myDate;
myDate = LocalDate.now().plus(2, ChronoUnit.DAYS);
LocalDateTime myDateAtTime = myDate.atTime(19,0,0);
long millis = myDateAtTime.toEpochSecond(ZoneOffset.UTC);

How to get the current date and time in seconds?, now() method: The Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC. This is known as the epoch time. It​  Example 1: Get the current date and time. In this example, Get-Date displays the current system date and time. The output is in the long-date and long-time formats. Get-Date Tuesday, June 25, 2019 14:53:32. Example 2: Get elements of the current date and time. This example shows how to use Get-Date to get either the

Without using Java 8 you can do something like this:

public static void main(String[] args) throws Throwable {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_YEAR, 2);
    c.set(Calendar.HOUR_OF_DAY, 19);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    System.out.println(c.getTimeInMillis() / 1000L); // Time in seconds in two days at 7:00 pm
}

You could also create a static method for this:

private static long timeInTwoDaysAt7pm() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_YEAR, 2);
    c.set(Calendar.HOUR_OF_DAY, 19);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    return c.getTimeInMillis() / 1000L;
}

Epoch Converter, Timestamp to Human date reset [batch convert] Convert seconds to days, hours and minutes. Seconds to How to get the current epoch time in Show code  The current date and time can be fetched by first creating a new Date object. Thereafter methods of the object can be called to get the date and time values. // new Date object let date_ob = new Date(); getDate : returns the day of the month (1-31)

If java 8 is a no go, then you can use Calendar :

import java.util.Calendar

Calendar calendar = Calendar.getInstance();

calendar.add(Calendar.DAY_OF_YEAR,  2);
calendar.set(Calendar.HOUR_OF_DAY, 19);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);

Date.now(), Convert your timestamp to datetime or date to timestamp with single click These examples are showing how to get current unix timestamp in seconds. -year -month -day -hour -minute -second These allow you to set individual items to be displayed in place of the current date/time. e.g. you could set the time to 12:00 CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.

Not sure if this is a correct approach or any better solution is there.

    Date dt = new Date();
    Calendar c = Calendar.getInstance();
    c.setTime(dt);
    c.add(Calendar.DATE, 2);
    c.set(Calendar.HOUR_OF_DAY, 19);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    long timeInSeconds = c.getTime().getTime() / 100;

Timestamp Converter, The Get-Date cmdlet gets a DateTime object that represents the current date or a date that you specify. Get-Date HH:mm, Time in 24-hour format -no seconds. Actually, it's safer to set the current timezone set on the device with Time.getCurrentTimezone(), or else you will get the current time in UTC. Time today = new Time(Time.getCurrentTimezone()); today.setToNow(); Then, you can get all the date fields you want, like, for example:

Get-Date, Date and time function syntax reference for various programming languages. The Current Unix Timestamp. 1588254502 seconds since Jan 01 1970. (UTC)  How do I get the current time in Python? The time module. The time module provides functions that tells us the time in "seconds since the epoch" as well as other utilities. import time Unix Epoch Time. This is the format you should get timestamps in for saving in databases. It is a simple floating point number that can be converted to an integer.

Unix Time Stamp, datetime.time : Stores the time in hours, minutes, seconds, and microseconds. This information is independent from any date; datetime.datetime :  In this article, you will learn to get today's date and current date and time in Python. We will also format the date and time in different formats using strftime() method. There are a number of ways you can take to get the current date.

How to Get the Current Date and Time in Python, Convert milliseconds to date - UNIX timestamp - UTC time. How to get the current time in milliseconds Leap seconds tend to cause trouble with software. You can use PHP date() function or DateTime() class to get current Date & Time in PHP. This tutorial will help you to get current date time in PHP. The provided results based on the timezone settings in the php.ini file. You may need to modify this setting to get date and time in the required timezone.

Comments
  • Have you tried anything yet?
  • Possible duplicate of Get date representation in seconds?
  • yes, tried joda-time but can't use it. Need to have solution using Date / Calendar object of java
  • What prevents you from using Java8 to get this thing done?
  • Why would you use Date and Calendar? This is like asking for directions, then specifying that you have to go on a horse.
  • Thank you for letting us know about this. +1
  • Or if you prefer: LocalDate.now().plusDays(2). Or LocalDate.now(ZoneId.systemDefault()).plusDays(2) to tell the reader we have chosen the device time zone consciously. May also want the same time zone for now and for toEpochSecond.
  • You're right ! I made some changes. Use add instead of set & set min and sec to 0
  • Note: the time in seconds should be milliseconds divided by 1000 and not 100. 1000 milliseconds is one second after all.
  • You don't need the first and third lines. Other than that, this looks identical to gil.fernandes' answer.
  • thanks for your input, will exclude first and third lines. Is is correct other than that ? @DawoodibnKareem
  • Well, since it's almost an exact duplicate of someone else's answer, yeah, it's correct. Apart from dividing by 100 on the last line, which should be 1000.