AnyLogic Date format - date

Is there a way to change the date format in AnyLogic, without constructing something with the implemented Time functions?
I want my Date to be displayed in such a way
"E dd.MM.yyyy HH:mm"
With the timefunctions I have problems, to get the date into the right format

Not sure what that E stands for, but if it's the timezone, you can get it with this:
ZoneId.of("Europe/Oslo").getDisplayName(TextStyle.SHORT_STANDALONE, Locale.ENGLISH)
I used Europe/Oslo there, but you can find the zone ids that you need here:
https://docs.oracle.com/middleware/12211/wcs/tag-ref/MISC/TimeZones.html
to use this you need to import libraries in Main/Advanced Java/Imports section
import java.time.ZoneId;
import java.time.format.TextStyle;
And then to get the required code with that format:
"E "+String.format("%02d", getDayOfMonth())+"."
+String.format("%02d",getMonth()+1)+"."
+String.format("%04d",getYear())+" "
+String.format("%02d",getHourOfDay())+":"
+String.format("%02d",getMinute())
You can replace the "E " with what I explained before
Or you can use whatever is currently your timezone... AnyLogic uses your computer timezone in order to know what timezone you are in:
Calendar cal=Calendar.getInstance();
cal.setTime(date());
String timezoneCode=cal.getTimeZone().toZoneId().getDisplayName(TextStyle.SHORT_STANDALONE, Locale.ENGLISH);

Related

DateFormat adding yy-mm-dd to DateTime when I specifically called for hh:mm

The code is as follows:
DateTime time = DateFormat("hh:mm").parse(doc[i]["Time"]);
The doc[i]["Time"] value is supposed to be a military time like 19:42. I followed the guidelines about using DateFormat but the end result variable time contains "1970-01-01 19:42:00.000". Is there a way for time to just contain "19.42"?
To get time in 24hrs format change your code to
String time = DateFormat("HH:mm").format(doc[i]["Time"]);
H -> is for 24 hours format
It is not possible to use DateTime to show a specific format, must always become a String.
A DateTime type will always store everything including year, month, hour, minutes, seconds, milliseconds, etc.
But when you later use the variable, you can chose what to display.
For example, you can chose to display just the military time. Here is one example using the Intl package (here)
Text(DateFormat('Hm').format(yourVariable))
Don't forget to import
import 'package:intl/intl.dart';

Matlab - isbusday and busdate format change

Would you be able to advise how can i change the format of the date the functions isbusday and busdate are using ?
The functions use US date format by default, but I need them to be in European format dd/mm/yyyy.
I have attempted to use the code below but it is not working.
isbusday('01-01-2015','dd-mm-yyyy')
busdate('01-01-2015','dd-mm-yyyy',1)
Thank you very much.
You want to convert your string to a datetime object. That is where you can control the format:
d = datetime('01-01-2015','InputFormat','dd-mm-yyyy');
isbusday(d)
busdate(t)
See the documentation: https://www.mathworks.com/help/matlab/ref/datetime.html and https://www.mathworks.com/help/finance/isbusday.html

Can Pandas (or Python) recognize today's date?

I was wondering if Pandas can somehow figure out what today's date is allowing me to automate the naming of the html file I create when I use the "df.to_html" method.
Basically I"m trying to read a website using method "pd.read_html", and then save the dataframe as an html file, daily. The name of the html file will be the day's date. (So today is 9/28/2016 and tomorrow will be 10/01/16 and so on ) I'm not particular about the format of the date, so Sept or 09, whichever is okay.
I'm trying to automate this as much as possible, and so far the best I've gotten is, using ".format" which allows me some flexiblity. But I don't know how I can further automate the process.
import pandas as pd
df = pd.read_html('random site')
today_date = 'saved data/{}.html'.format('Sept 28') # I'm saving it in the folder "saved data" with the name as today's date.html.
df.to_html(today_date)
Thanks.
See the datetime module.
specifically: datetime.date.today().isoformat() gives you a string with the current date in ISO 8601 format (‘YYYY-MM-DD’)

Trying to get the current date with a specific format but Date is coming with a expected way

Here is the code and output. Please let me know what's wrong with the code.
import java.text.SimpleDateFormat
def myDate=new Date()
def sdf= new SimpleDateFormat("MM/DD/YYYY")
return sdf.format(myDate)
log.info sdf.format(myDate)
Op-: 04/94/2016
Thanks!
You need lower case dd AND yyyy
You can also call format on dates directly in groovy
date.format('MM/dd/yyyy')
Also, if this is to be read by anyone outside the US, or you want to be able to sort dates alphabetically, consider the more universal (iso8601) format of
date.format('yyyy-MM-dd')
As AR.3 said in their answer, the documentation for simpledateformat can be found here

Converting a string timestamp to Date results in reset to UNIX epoch

I'm having some problems converting a string to a date object in google apps script.
My dates are in the following format, from a 3rd party API:
2013-01-17T17:34:50.507
I am attempting to convert this to a Date object:
return Date(stringDate);
And this is being returned:
Thu Jan 01 01:00:00 GMT+01:00 1970
Can someone tell me what i'm doing wrong, and how to resolve this issue ?
With moment.js, it is as easy as this to parse any of ISO 8601 format.
var date = Moment.moment("2013-01-17T17:34:50.507").toDate();
You can use moment.js to parse your arbitrary date string as well.
To use moment.js in GAS, you just need to add it in the script editor.
Open your script in GAS script editor and go to "Resources" then "Libraries...", then put this project key MHMchiX6c1bwSqGM1PZiW_PxhMjh3Sh48 and click "Add". Choose the version from the dropdown, then click "Save". Now, you are ready to use moment.js in GAS.
moment.js can be used to parse date string, create formatted date string, and many other date manipulation. Thanks to the author!
You can find the moment.js documentation here.
It doesn't appear that the Date object knows how to handle that date. The date is in ISO 8601 format. Javascript can handle Dates if they are given timezone information.
You will have to do some testing, but if those dates given to you are in UTC time, then just add a Z to the end of the date string before you call new Date().
Edit: The Apps Script Date object can't seem to handle a timezone other than UTC when parsing a Date. I opened an issue for it.
It doesn't work in GScript, at least for me at the time I'm writing it.
This post serves a working alternative: How do I format this date string so that google scripts recognizes it?
As of now new Date() seems to work:
var dT = new Date("2013-01-17T17:34:50.507");
console.info("dT: %s or %d", dT, dT.getTime());
returns dT: Thu Jan 17 17:34:50 GMT+01:00 2013 or 1.358440490507E12 in Google Apps Script