Tag Archives: Date Class

Converting date into string format in Python, Javascript, Java and Ruby

By | December 30, 2023

Pythonfrom datetime import datetimedate_object = datetime.now()date_string = date_object.strftime(“%Y-%m-%d %H:%M:%S”)print(date_string) JavaScriptconst currentDate = new Date();const dateString = currentDate.toISOString(); // Adjust the format as neededconsole.log(dateString); Javaimport java.text.SimpleDateFormat;import java.util.Date; public class DateToString {public static void main(String[] args) {Date currentDate = new Date();SimpleDateFormat dateFormat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);String dateString = dateFormat.format(currentDate);System.out.println(dateString);}} Rubyrequire ‘date’current_date = DateTime.nowdate_string = current_date.strftime(‘%Y-%m-%d %H:%M:%S’)puts date_string… Read More »