If the variable cannot be used in monaca

Asked 1 months ago, Updated 1 months ago, 2 views

I'm trying to calculate the date and time.
Codepen shows the results in the log without any problems, but
If you try monaca, it will be null.
It was not possible to specify the date and time directly for the new Date() instead of the variable.
I don't know the cause, thank you for your cooperation.


vara = new Date(gg);       
varb = new Date(ff);           
vardd = a-b;    

javascript monaca jquery

2022-09-30 13:50

2 Answers

I can't say for sure because I don't have running environment information (IDE preview or iOS/Android debugger), but I remember that I couldn't use console.log with iOS version of Monaca debugger.

When I ran the source provided, my environment (Windows 8.1, Chrome 43, iOS 8.3, Monaca Debugger 4.0.1) didn't even print null in the first place.

According to the official documentation,

As for iOS apps, the Mac's Safari remote debugging capability and Monaca debugger can be combined to perform debugging.This allows you to use the following features:
Debugging using the Console—Provides message output and debug sessions on the Console.


It says.Conversely, if you don't use the Mac+Safari remote debugging feature, you can read that console is not available.I was able to confirm that the IDE preview would output console.log, although the iOS Monaca debugger did not output anything.

There is a bug-prone issue with the JavaScript code provided.
The date format string passed to the Date object does not conform to the standard format and is therefore not interpreted correctly depending on the browser implementation.
(After executing the source code provided, Chrome 43 said 180,000 but Firefox 38 said NaN.)

I don't know how iOS/Android WebView interprets the format '2015-12-3123:59', but for safety reasons, it should be in some standard format (the following is an example of ISO 8601).

vara = new Date(gg);
varb = new Date(ff);
vardd = a-b;

Please refer to the following page for the format of the date string.

2022-09-30 13:50

iOS Debugger (4.0.1), on iOS 8.3 and
Android Debugger (4.0.2), on Android 5.1.1 Verified in .

Don't worry, the console.log content will appear on the device.

The main reason why console.log(dd); is null is that gg and ff are not properly recognized as date strings, and a and b fail to generate date objects.

Now, how should I write it on gg and ff?

vargg='2015/12/31 23:59';

and so on.
In other words, the date and time should be separated by 」/ に instead of -- 」, or
If you want to follow the format, use yyyy-mm-ddTtt:mm:ss.sss+mm:ss (where +09:00 is Japan Standard Time).

vargg='2015/12/31 23:59';
vara = new Date(gg);
varb = new Date(ff);
console.debug("a-localestr" + a.toLocaleString());
console.log("b-localestr" + b.toLocaleString());
console.debug("a-gettime" + a.getTime());
console.log("b-gettime" + b.getTime());
vardd = a-b; 
varee = a.getTime()-b.getTime();

2022-09-30 13:50

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.