If you’re building a website or web app that targets a Nepali audience, adding a Bikram Sambat (BS) ↔ Anno Domini (AD) date converter can be a highly beneficial feature. In this post, you’ll learn how to implement a lightweight, plugin-free BS to AD and AD to BS converter using HTML, CSS, and JavaScript, powered by the @sbmdkl/nepali-date-converter
module.
Whether you’re a developer, blogger, or someone running a WordPress site, this guide shows you how to copy and paste a few lines of code to get the job done!
This simple tool allows users to:
It’s mobile-friendly, styled, and ready to embed directly into any page—no need for external plugins or frameworks.
Let’s break down the code snippet:
adToBs()
and bsToAd()
from esm.sh CDN.window.BsAdConverter
is a global object storing the functions for easy access later.Tip: Since we’re using
type="module"
, this works in all modern browsers without any bundler.
div
contains two main input areas:
<input type="date">
for selecting a Gregorian date.<p>
tags for showing results.javascriptCopyEditfunction handleAdToBs() { const ad = document.getElementById(“ad-date”).value; if (!ad) { alert(“Please pick a valid AD date.”); return; } const bs = window.BsAdConverter.adToBs(ad); document.getElementById(“bs-result”).innerText = bs ? “BS Date: ” + bs : “Invalid AD date.”; }
adToBs()
.javascriptCopyEditfunction handleBsToAd() { const bs = document.getElementById(“bs-date”).value; const isValid = /^\d{4}-\d{2}-\d{2}$/.test(bs); if (!isValid) { alert(“Please enter a valid BS date in YYYY-MM-DD format.”); return; } const ad = window.BsAdConverter.bsToAd(bs); document.getElementById(“ad-result”).innerText = ad ? “AD Date: ” + ad : “Invalid BS date.”; }
bsToAd()
and displays the AD date.Paste the following into any HTML page or a WordPress page (using HTML block):
Contact me for more customisation.
This lightweight BS ↔ AD date converter is easy to implement, doesn’t rely on plugins or backend logic, and works perfectly in modern browsers. It’s a great addition to websites aimed at a Nepali audience or educational content requiring dual calendar support.
If you’re looking to take it further, consider adding offline support, date validation, or even voice input for accessibility!