Free coupon for initial registration

Get current date time in the format of YYYY/MM/DD hh:mm:ss

Contents [hide]

Output

2019/12/09 07:05:25

Programming code example

Go

1
2
3
4
5
6
7
8
package main
import "fmt"
import "time"
  
func main() {
    jst, _ := time.LoadLocation("Asia/Tokyo")
    fmt.Println(time.Now().In(jst).Format("2006/01/02 15:04:05"))
}

JavaScript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
console.log(formatDate(new Date()));
 
function formatDate(date) {
    var d = new Date(date),
    month = '' + (d.getMonth() + 1),
    day = '' + d.getDate(),
    hour = d.getHours(),
    min = d.getMinutes(),
    sec = d.getSeconds();
 
    year = d.getFullYear();
    if (month.length < 2)
        month = '0' + month;
 
    if (day.length < 2)
        day = '0' + day;
 
    if (hour.length < 2)
        hour = '0' + hour;
 
    if (min.length < 2)
        min = '0' + min;
 
    if (sec.length < 2)
        sec = '0' + day;
    return [year, month, day].join('/')+' '+[hour, min, sec].join(':');
}

Perl

1
2
use POSIX qw(strftime);
print(strftime("%Y/%m/%d %H:%M:%S", localtime())."\n");

PHP

1
2
3
<?php
date_default_timezone_set('Asia/Tokyo');
echo date('Y/m/d H:i:s');

Python

1
2
from datetime import datetime
print( datetime.now().strftime("%Y/%m/%d %H:%M:%S") )

Ruby

1
puts Time.now.strftime("%Y/%m/%d %H:%M:%S")

Rust

Corgo.toml

1
2
3
4
5
6
7
8
9
10
[package]
name = "date_time"
version = "0.0.1"
 
[dependencies]
chrono = "*"
 
[[bin]]
name = "date_time"
path = "date_time.rs"
Programming code
1
2
3
4
5
6
7
extern crate chrono;
use chrono::{Local, DateTime};
 
fn main() {
  let now: DateTime<Local> = Local::now();
  println!("{}", now.format("%Y/%m/%d %H:%M:%S"))
}

Shell

1
2
DATE=`date '+%Y/%m/%d %H:%M:%S'`;
echo $DATE;

You can find programming examples to solve same problem using multiple programming languages.
Please find best programming language for your problems and solution.
Covering all cases: JavaScript Perl PHP Python Ruby | Covering some cases: C C++ C# Go Java Rust Shell
 
Big categories
Array | Class | Database | File systems | Network | Number | String | System | Test | Time | Variable
Other useful content
  1. Popular programming languages
  2. Popular web framework
  3. VPS Ranking.com (Find best VPS based on benchmark)
Free coupon for initial registration