setDate not setting date properly inside eval in batch script - mongodb

--eval "var date = new Date(); date.setDate(date.getDate()-10)"'
pause
new Date() gives me the current date. I'm trying to get 10 days back date,but setDate() not setting the date correctly.I'm doing it through batch script.
I got this 1576031482772 after evaluating date.setDate(date.getDate()-10) .Please help me find a solution.

This is the expected behavior. The signature of setDate is as follows. ref
Parameters
It accepts one parameter, it should be number as a day value.
Return Value
It returns milliseconds between 1 January 1970 00:00:00 UTC and the given date
Solution
You are actually setting the day value of date. So If you want to retrieve the value, just use date.getDate(). Which will be the new date.
For more details, how it works, you can refer MDN.

Related

How to get a specific date of next month? (Java 8)

With today's date, I should get the 16th date of next month.
For example, on passing 13-12-2021, I should get 16-01-2022.
I need to get the next month 16th day from current date (input date). Examples:
On passing 13-11-2021 should get 16-12-2021.
On passing 14-11-2021 should get 16-12-2021.
On passing 15-11-2021 should get 16-12-2021.
On passing 02-12-2021 should get 16-01-2022.
On passing 03-12-2021 should get 16-01-2022.
On passing 03-01-2022 should get 16-02-2022.
On passing 04-01-2022 should get 16-02-2022.
Any help will be much appreciated. Thanks.
java.time
One of the many strong points of java.time, the modern Java date and time API, is date arithmetic like this.
public static LocalDate nthDayOfFollowingMonth(
int desiredDayOfMonth, LocalDate currentDate) {
return YearMonth.from(currentDate)
.plusMonths(1)
.atDay(desiredDayOfMonth);
}
Try it out with your example date:
System.out.println(nthDayOfFollowingMonth(
16, LocalDate.of(2021, Month.DECEMBER, 13)));
Output:
2022-01-16
We might not have needed to convert to YearMonth and back to LocalDate. Doing so relieves both me and the reader of considering what happens if today’s day of month doesn’t exist in next month — for example if current date is 30 January (there is no 30 February). What one still wants to consider is what happens if you request a day of month tht doesn’t exist next month. For example on 13 January asking for the 30th of next month. We can try that out too:
System.out.println(nthDayOfFollowingMonth(
30, LocalDate.of(2022, Month.JANUARY, 13)));
I find the result very reasonable:
java.time.DateTimeException: Invalid date 'FEBRUARY 30'

Flutter: DateTime fromMillisecondsSinceEpoch shows one day less

I get a time value from an API which is a unix value, but when i use DateTime.fromMillisecondsSinceEpoch, it shows one day less. I don't understand why. Please explain me what i'm doing wrong.
I think timezones made the problem, but i don't know how to fix it.
Unix value from API
1623283201 // 2021-06-10 0:00:01.000
This is my code
var date = DateTime.fromMillisecondsSinceEpoch((json['time_last_update_unix']) * 1000);
print("This is the date " + date.toString()); // 2021-06-09 20:00:01.000
If your date input carrying a time zone which is not your local timezone, you have to explicitly change the following bool value
bool isUtc = true
Default value is false and date is identified from your local timezone.
For more detail please refer this link
https://api.flutter.dev/flutter/dart-core/DateTime/DateTime.fromMillisecondsSinceEpoch.html

startOfDay date converted when printed

I'm in a GMT+1 timezone.
Function startOfDay should return "the first moment of the given date".
In my case for date "2020-11-10 19:52:52 +0000\n" I should get "2020-11-10 00:00:00 +0000\n", but I'm getting "2020-11-09 23:00:00 +0000\n" (desired time - 1 hour).
As you can see in the screenshot, variable is set up correctly, but when I try to print it, it is magically converted. It looks like swift is converting it on the fly, but why?
At first, I thought that maybe somehow I have different timezone for Calendar object, but when I print Calendar.current.timeZone.abbreviation() the result is "GMT+1", same as for Date object or TimeZone.current.abbreviation().
Xcode playground

How can I compare and check date of program and the system date in MVS 2012 Coded UI test?

I am trying to compare and check the date if it is today's date or not in a spesific program. I tried to use assertion method but when I use it the time will remain same if you try it next day. The main problem that I need to know when open a page from program It should be today's date and should be passed. if you know already anything about it please let me know also :)
Thanks yo!
Use System.DateTime.Now.ToString("yyyy-MM-dd") as one argument of the assertion. You may need to use a different format rather in the ...ToString() method. The exact format depends on how the date is shown on the screen.
This could be done using "StringAssert" to verify that your programs date string contains today's date string, while ignoring the time:
var programDateString = "7/25/2016 12:00:00"; //this is an example of your date retrieved from the application with time included
var todaysDate = System.DateTime.Today.ToShortDateString(); //short date string
StringAssert.Contains(programDateString, todaysDate);

EXSLT date:add function has unexpected results

I want to get tomorrows date using exslt date.
date:date() returns todays date ('2014-01-23') and if I am adding 1 day ('P1D'), I expect it to be tomorrow ('2014-01-24'). But instead the result of
<xsl:value-of select="date:add(date:date(), 'P1D')"/>
is '2014-01-23T23:00:00Z'.
It took me some time of research but finally I solved the problem:
The problem with my previous implementation was caused by the timezone. The exact return value of date:date() is '2014-01-23+01:00' (a date with timezone; for me it's +01:00).
Adding a duration via date:add(string, string) seems to have a problem with that. So to get the correct result I just cut off the timezone from todays date. The result of
<xsl:value-of select="date:add(substring(date:date(), 1, 10), 'P1D')"/>
is tomorrows date ('2014-01-24') as expected.