browse by category or date

For most of us, Date formatting in JavaScript is handled by external library/plugin (jQuery’s dateFormat, jQuery-UI’s datepicker). But if somehow your project has no access to them, you can extend Date by yourself.

window.Date.prototype.format = function(fmt){
	if (!fmt) return this.toString();
	
	var rgx = /[a-zA-Z]+/g;
	if (fmt.replaceAll) {
		var year = this.getFullYear().toString();
		var month = this.getMonth();
		var date = this.getDate();            
		var arMonths = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN",
			"JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
		var that = this;
		fmt = fmt.replaceAll(rgx, function (f) {
			switch (f) {
				case "yyyy": return year;
				case "yy": return year.substr(2);
				case "MMM": return arMonths[month];
				case "dd": return date.toString().padStart(2, "0"); 
			}
			return f;
		});
	}
	return fmt;
}

Now you can the new format function in the Date class

As shown above, if format function is unable to handle the format string specified, it will just returns the original text. What you need to do now is to add the new case inside switch(f){ …. }. For example, we want to handle HH format.

			switch (f) {
				// ... SNIP ...
				case "HH": return that.getHours().toString().padStart(2, "0");
			}

Now, we should see the correct value.

I hope it helps. Cheers!

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

If you’re a primary school students struggling to remember the multiplications, hopefully this will help you to master it.

Have fun and collect these trophies!!!

To play the game, just select the number, then click Start button. To answer, type the number then press ENTER key.

Good luck!

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant:

So how to create above chart? Apparently it’s very simple. What you need are:

  1. COVID-19 Data

    One of the best source of COVID-19 data is provided by Center for Systems Science and Engineering (CSSE) at Johns Hopkins University. You can clone their data from HERE. Use master branch. Open .\csse_covid_19_data\csse_covid_19_time_series\time_series_covid19_confirmed_global.csv

  2. Basic Excel skills

    Since I’m only interested with the countries nearby to Indonesia. I need to filter out most countries and consolidate multiple rows into one (Australia has more than one rows as their data is at State/Province level). The last thing I need to do is to format the time-series header.

    So what I did is converting from this CSV:

    into this:

  3. Flourish account

    Sign-up to Flourish using your Google account. Upload the CSV produced in step 2. You should have something like this:

    We then need to configure the columns:

    And that’s it. All left is to tweak the appearance, how fast the animation, etc. There are many options to explore. I’ll let you explore that on your own.

That’s all folks. I hope it helps. Cheers!

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Possibly relevant: