QA Graphic

PlayWrite Date format

Typescript vs Python

Amazing how easier it is to get the date format for saving screenshots. Why is it so complicated in Typescript?

Here's getting the date in YYYY-MM-DD-HH-MM format:

Typescript


function getCurrentDateTimeFormatted(): string {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed
  const day = String(now.getDate()).padStart(2, '0');
  const hours = String(now.getHours());
  const minutes = String(now.getMinutes());
  return `${year}-${month}-${day}-${hours}-${minutes}`;
}
// Example usage
const formattedDateTime = getCurrentDateTimeFormatted();

Python


from datetime import datetime
datefile = datetime.now().strftime("%Y-%m-%d-%H-%M")

 

Comments

Add Your Comments