The Wayback Machine - https://web.archive.org/web/20240905185537/https://www.geeksforgeeks.org/convert-timestamp-to-readable-date-time-in-php/
Open In App

Convert timestamp to readable date/time in PHP

Last Updated : 01 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Problem: Convert timestamp to readable date/time in PHP
Solution: This can be achieved with the help of date() function, which is an inbuilt function in PHP can be used to format the timestamp given by time() function. This function returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

Example 1:




<?php
echo date('m/d/Y H:i:s', 1541843467);
?>


Output:

11/10/2018 09:51:07

Example 2:




<?php
echo date('m/d/Y H:i:s', time());
?>


Output:

Current Time in formatted form

Reference: http://php.net/manual/en/function.date.php

PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.


Previous Article
Next Article

Similar Reads

Node.js Stream readable.readable Property
The readable.readable property is an inbuilt application programming interface of Stream module which is used to check if it is safe to call readable.read() method. Syntax: readable.readable Return Value: It returns true if readable.read() method is being called otherwise returns false. Below examples illustrate the use of readable.readable propert
1 min read
Node.js Readable Stream readable Event
The 'readable' Event in a Readable Stream is emitted when the data is available so that it can be read from the stream or it can be emitted by adding a listener for the 'readable' event which will cause data to be read into an internal buffer. Syntax: Event: 'readable' Below examples illustrate the use of readable event in Node.js: Example 1: // No
1 min read
JavaScript Convert bytes to human-readable string
Given the size of a file (in Bytes), the task is to convert it into human-readable form using JavaScript. Here are a few methods to discuss. Example 1: This example converts the file Size(in Bytes) into human-readable form. It shows the values in decimal and for less than 1024 Bytes, it remains in Bytes. C/C++ Code let size = function (bytes) { if
2 min read
How to convert timestamp to time ago in PHP ?
Given a time and the task is to convert timestamp to time ago. The time ago format removes the problem of different time zones conversions. Given below is a function to do the time conversions. In this function, taking the timestamp as an input and then subtract it from the current timestamp to convert it into the time ago format. To make this func
3 min read
How to format a phone number in Human-Readable using JavaScript ?
Give a phone number and the task is to format a phone number in such a way that it becomes easy to understand for humans. There are two approaches to format the numbers which are discussed below: Using RegExpUsing substr() MethodApproach 1: Using RegExpA RegExp is used to replace the original phone number with a human-readable phone number.The RegE
1 min read
Node.js Stream readable.pause() Method
The readable.pause() method is an inbuilt application programming interface of Stream module which is used to stop the flowing mode from emitting 'data' events. If any data that becomes accessible will continue to exist in the internal buffer. Syntax: readable.pause() Parameters: This method does not accept any parameters. Return Value: If this met
2 min read
Node.js Stream readable.isPaused() Method
The readable.isPaused() method is an inbuilt application programming interface of Stream module which is used to check the current operating state of the Readable streams. Syntax: readable.isPaused() Parameters: This method does not accept any parameters. Return Value: It returns true if the Readable state is paused otherwise returns false. Below e
1 min read
Node.js Stream readable.destroyed Property
The readable.destroyed property is an inbuilt application programming interface of Stream module which is used to check the readable.destroy() function is being called or not. Syntax: readable.destroyed Return Value: It returns true if readable.destroy() method is being called otherwise returns false. Below examples illustrate the use of readable.d
2 min read
Node.js Stream readable.destroy() Method
The readable.destroy() method is an inbuilt application programming interface of Stream module which is used to destroy the stream. Syntax: readable.destroy( error ) Parameters: This method accepts single parameter error which is optional and it emits an error while handling error event. Return Value: If this method is used then the stream is destr
2 min read
Node.js Stream readable.read() Method
The readable.read() method is an inbuilt application programming interface of Stream module which is used to read the data out of the internal buffer. It returns data as a buffer object if no encoding is being specified or if the stream is working in object mode. Syntax: readable.read( size ) Parameters: This method accepts single parameter size wh
2 min read
Node.js Stream readable.readableEncoding Property
The readable.readableEncodin property in a readable Stream is utilized to get the property encoding of a stated readable stream. Moreover, you can set this property using readable.setEncoding() method. Syntax: readable.readableEncoding Return Value: It returns the encoding used in the program. Below examples illustrate the use of readable.readableE
2 min read
Node.js Stream readable.readableEnded Property
The readable.readableEnded property in a readable Stream is utilized to check if the end event is emitted or not. Syntax: readable.readableEnded Return Value: It returns true if end event is emitted else it returns false. Below examples illustrate the use of readable.readableEnded property in Node.js: Example 1: // Node.js program to demonstrate th
1 min read
Node.js Stream readable.readableFlowing Property
The readable.readableFlowing property in a readable stream that utilized to check if the streams are in flowing mode or not. Syntax: readable.readableFlowing Return Value: It returns true if stream is in flowing mode else it returns false. Below examples illustrate the use of readable.readableFlowing property in Node.js: Example 1: // Node.js progr
1 min read
Node.js Stream readable.readableHighWaterMark Property
The readable.readableHighWaterMark property in a readable stream that is used to check the value of highWaterMark used while constructing Readable streams. Syntax: readable.readableHighWaterMark Return Value: It returns the value of highWaterMark used while constructing Readable streams. Below examples illustrate the use of readable.readableHighWat
1 min read
Node.js Stream readable.readableLength Property
The readable.readableLength property in a readable Stream that is used to check the number of bytes in the queue which is ready to be read. Syntax: readable.readableLength Return Values: It returns the number of bytes in the queue which are ready to be read. Below examples illustrate the use of readable.readableLength property in Node.js: Example 1
1 min read
Node.js Stream readable.readableObjectMode Property
The readable.readableObjectMode property in a Readable Stream that is used to check the objectMode of the stream. Syntax: readable.readableObjectMode Return Value: It returns the Boolean value. Below examples illustrate the use of readable.readableObjectMode property in Node.js: Example 1: // Node.js program to demonstrate the // readable.readableO
2 min read
Node.js Stream readable.pipe() Method
The readable.pipe() method in a Readable Stream is used to attach a Writable stream to the readable stream so that it consequently switches into flowing mode and then pushes all the data that it has to the attached Writable. Syntax: readable.pipe( destination, options ) Parameters: This method accept two parameters as mentioned above and described
2 min read
Node.js Stream readable.unpipe() Method
The readable.unpipe() method in a Readable Stream is used to detach a Writable stream which was previously attached while using the stream.pipe() method. Syntax: readable.unpipe( destination ) Parameters: This method accepts single parameter destination which is the destination of writable stream to be detached. Return Value: It returns stream.Writ
1 min read
Node.js Stream readable.setEncoding() Method
The readable.setEncoding() method in a Readable Stream is used to set the encoding of the data read. Syntax: readable.setEncoding( encoding ) Parameters: This method accepts single parameter encoding which holds the encoding type. Return Value: It returns the data in the encoded form. Below examples illustrate the use of readable.setEncoding() meth
1 min read
Node.js Stream readable.unshift() Method
The readable.unshift() method in a Readable Stream is utilized to push a chunk of data back into the internal buffer. However, when a stream is being fully consumed and it needs to be "un-consumed" then this method is helpful. Syntax: readable.unshift( chunk, encoding ) Parameters: This method accept two parameters as mentioned above and described
2 min read
Node.js Stream readable[Symbol.asyncIterator]() Method
The readable[Symbol.asyncIterator]() method in a Readable Stream is utilized to fully consume the stream. Syntax: readable[Symbol.asyncIterator]() Parameters: This method does not accept any parameters. Return Value: It returns asyncIterator to fully consume the stream. Below examples illustrate the use of readable[Symbol.asyncIterator]() method in
1 min read
Node.js Readable Stream error Event
The 'error' event in Readable stream can be emitted at any time. It takes place when the hidden stream is not able to generate data due to some hidden internal failure or when the implementation of stream pushes a chunk of data which is not valid. Moreover, a single Error object is passed as an argument to the listener callback. Syntax: Event: 'err
1 min read
Node.js Readable Stream end Event
The 'end' Event in a Readable Stream is emitted when there is no available data to be consumed from the readable stream. And the 'end' event won't be emitted if the data is not fully consumed. It can be done by switching the stream into the flowing mode, or by calling stream.read() method again and again until all the data is being consumed. Syntax
2 min read
Node.js Readable Stream data Event
The 'data' Event in a Readable Stream is emitted when readable.pipe() and readable.resume() method is called for switching the stream into the flowing mode or by adding a listener callback to the data event. This event can also be emitted by calling readable.read() method and returning the chunk of data available. Syntax: Event: 'data' Below exampl
2 min read
Node.js Readable Stream close Event
The 'close' Event in a Readable Stream is emitted when the stream and any of its hidden resources are being closed This event implies that no further events can be emitted, and no further computations can take place. Moreover, if a Readable stream is created with the emitClose option then it can always emit 'close' event. Syntax: Event: 'close ' Be
1 min read
Node.js Readable Stream resume Event
The 'resume' Event in a Readable Stream is emitted when stream.resume() is being called and readableFlowing property is not true. Syntax: Event: 'resume' Return Value: It is emitted if readable.resume() is being called else it is not emitted. Below examples illustrate the use of resume event in Node.js: Example 1: // Node.js program to demonstrate
2 min read
Node.js Readable Stream pause Event
The 'pause' Event in a Readable Stream is emitted when stream.pause() is being called and readableFlowing property is not false. Syntax: Event: 'pause' Return Value: It is emitted if readable.pause() is being called else it is not emitted. Below examples illustrate the use of pause event in Node.js: Example 1: // Node.js program to demonstrate the
1 min read
Node.js stream.Readable.from() Method
The stream.Readable.from() method is an inbuilt application programming interface of the Stream module which is used to construct Readable Streams out of iterators. Syntax: stream.Readable.from( iterable, options ) Parameters: This method accept two parameters as mentioned above and described below: iterable: It is an object which implements the Sy
2 min read
Node.js Stream readable.resume() Method
Node.js streams are powerful tools for handling data transfer efficiently, especially when dealing with large datasets or real-time data. The readable.resume() method is a part of the readable stream interface, playing a crucial role in managing the flow of data. This article will delve into what readable.resume() does, how it works, and when to us
4 min read
How to Convert a Date String to Timestamp in JavaScript ?
In this article, we are going to learn about the conversion of Date strings to Timestamps by using JavaScript. Converting date strings to timestamps means translating human-readable date representations into numeric values, indicating the time's position in milliseconds since January 1, 1970. Several methods can be used to Convert a Date String to
2 min read