avatar
get day name from unix timestamp PHP

• Take advantage of using the strtotime() function, along with the DateTimeZone and DateTime classes. For example:

» PHP

$dateString = "08-07-2023";

$timezone = new DateTimeZone('Asia/Singapore');
$date = DateTime::createFromFormat('d-m-Y', $dateString, $timezone);

echo $date->format('l');

» Javascript

let dateString = "08-07-2023";

let timezone = "Asia/Singapore";
let [day, month, year] = dateString.split("-");
let timestamp = Date.parse(`${month}-${day}-${year}`);
let date = new Date(timestamp);
let options = { timeZone: timezone, weekday: 'long' };
let formattedDay = new Intl.DateTimeFormat('en-US', options).format(date);

console.log(formattedDay);

» Java

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Main {
    public static void main(String[] args) {
        String dateString = "08-07-2023";
        String timezone = "Asia/Singapore";

        SimpleDateFormat inputFormat = new SimpleDateFormat("dd-MM-yyyy");
        SimpleDateFormat outputFormat = new SimpleDateFormat("EEEE");
        outputFormat.setTimeZone(TimeZone.getTimeZone(timezone));

        try {
            Date date = inputFormat.parse(dateString);
            String formattedDay = outputFormat.format(date);
            System.out.println(formattedDay);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

» Python

from datetime import datetime
import pytz

date_string = "08-07-2023"
timezone = "Asia/Singapore"

date_format = "%d-%m-%Y"
date = datetime.strptime(date_string, date_format)

timezone_obj = pytz.timezone(timezone)
date_with_timezone = timezone_obj.localize(date)

formatted_day = date_with_timezone.strftime("%A")
print(formatted_day)
24
get unix timestamp javascript get year month day from UNIX timestamp
You need to login to do this manipulation!