Способы создания текущей даты в формате ддммгггг на нескольких языках программирования

Вот несколько способов создания текущей даты в формате «ддммгггг» на различных языках программирования:

  1. Python:

    from datetime import date
    current_date = date.today().strftime("%d%m%Y")
    print(current_date)
  2. JavaScript:

    const today = new Date();
    const day = String(today.getDate()).padStart(2, '0');
    const month = String(today.getMonth() + 1).padStart(2, '0');
    const year = today.getFullYear();
    const current_date = day + month + year;
    console.log(current_date);
  3. Java:

    import java.time.LocalDate;
    import java.time.format.DateTimeFormatter;
    public class Main {
    public static void main(String[] args) {
        LocalDate currentDate = LocalDate.now();
        String formattedDate = currentDate.format(DateTimeFormatter.ofPattern("ddMMyyyy"));
        System.out.println(formattedDate);
    }
    }
  4. C#:

    using System;
    public class Program {
    public static void Main(string[] args) {
        DateTime currentDate = DateTime.Now;
        string formattedDate = currentDate.ToString("ddMMyyyy");
        Console.WriteLine(formattedDate);
    }
    }
  5. Рубин:

    require 'date'
    current_date = Date.today.strftime("%d%m%Y")
    puts current_date
  6. PHP:

    $current_date = date("dmY");
    echo $current_date;
  7. Идем:

    package main
    import (
    "fmt"
    "time"
    )
    func main() {
    currentDate := time.Now().Format("02012006")
    fmt.Println(currentDate)
    }
  8. Скорость:

    import Foundation
    let currentDate = DateFormatter.localizedString(from: Date(), dateStyle: .short, timeStyle: .none)
    let formattedDate = currentDate.replacingOccurrences(of: "/", with: "")
    print(formattedDate)
  9. Ржавчина:

    use chrono::prelude::*;
    fn main() {
    let current_date = Utc::today().format("%d%m%Y").to_string();
    println!("{}", current_date);
    }
  10. Котлин:

    import java.time.LocalDate
    import java.time.format.DateTimeFormatter
    fun main() {
    val currentDate = LocalDate.now()
    val formattedDate = currentDate.format(DateTimeFormatter.ofPattern("ddMMyyyy"))
    println(formattedDate)
    }
  11. C++:

    #include <iostream>
    #include <ctime>
    #include <iomanip>
    int main() {
    std::time_t t = std::time(nullptr);
    std::tm* now = std::localtime(&t);
    std::cout << std::put_time(now, "%d%m%Y") << std::endl;
    return 0;
    }