кодесурса
«MYSQL

MySQL UTC_TIME () функция

script1adsense2code
script1adsense3code

UTC_TIME () функция

MySQL UTC_TIME возвращает текущее время UTC в виде значения в формате «ЧЧ: ММ: СС» или ЧЧММСС в зависимости от контекста функции, то есть в строковом или числовом контексте.

Синтаксис:

 UTC_TIME; UTC_TIME ()

Синтаксическая диаграмма: 1

«MySQL

Синтаксическая диаграмма: 2

«MySQL

Версия MySQL: 5.6


Видео презентация

Иллюстрированная презентация

«Иллюстрированные

Пример: функция MySQL UTC_TIME ()

Следующая инструкция вернет текущее время UTC.

Код:

SELECT UTC_TIME,UTC_TIME();

Пример вывода:

 mysql> SELECT UTC_TIME, UTC_TIME ();
+ ---------- + ------------ +
| UTC_TIME | UTC_TIME () |
+ ---------- + ------------ +
| 22:26:15 | 22:26:15 | 
+ ---------- + ------------ +
1 ряд в наборе (0,02 сек)

Примечание . Приведенный выше вывод показывает время UTC во время выполнения команды. Значения выходного кода ниже могут отличаться, так как он покажет время UTC, когда вы нажмете Просмотр примера в браузере .

PHP скрипт

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>example-utc_time-function - php mysql examples | w3resource</title>
<meta name="description" content="example-utc_time-function - php mysql examples | w3resource">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Current UTC time in two different ways:</h2>
<table class='table table-bordered'>
<tr>
<th>Current UTC time using UTC_TIME</th><th>Current UTC time using UTC_TIME()</th>
</tr>
<?php
$hostname="your_hostname";
$username="your_username";
$password="your_password";
$db = "your_dbname";
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
foreach($dbh->query('SELECT UTC_TIME,UTC_TIME()') as $row) {
echo "<tr>";
echo "<td>" . $row['UTC_TIME'] . "</td>";
echo "<td>" . $row['UTC_TIME()'] . "</td>";
echo "</tr>";
}
?>
</table>
</div>
</div>
</div>
</body>
</html>

Посмотреть пример в браузере

JSP скрипт

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>example-utc_time-function</title>
</head>
<body>
<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String Host ="jdbc:mysql://localhost:3306/w3resour_bookinfo";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
connection = DriverManager.getConnection(Host, "root", "datasoft123");
statement = connection.createStatement();
String Data ="SELECT UTC_TIME,UTC_TIME()";
rs = statement.executeQuery(Data);
%>
<TABLE border="1">
<tr width="10" bgcolor="#9979">
<td>Current UTC time using UTC_TIME</td>
<td>Current UTC time using UTC_TIME()</td>
</tr>
<%
while (rs.next()) {
%>
<TR>
<TD><%=rs.getString("UTC_TIME")%></TD>
<TD><%=rs.getString("UTC_TIME()")%></TD>
</TR>
<%   }    %>
</table>
<%
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
out.println("Can’t connect to database.");
}
%>
</body>
</html>

Пример функции MySQL UTC_TIME () в числовом формате

Следующая инструкция вернет текущее время UTC в числовом формате.

SELECT UTC_TIME()+0;

Пример вывода:

 mysql> SELECT UTC_TIME () + 0;
+ --------------- +
| UTC_TIME () + 0 |
+ --------------- +
| 222924.000000 | 
+ --------------- +
1 ряд в наборе (0,01 с)

PHP скрипт

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>example1-utc_time-function - php mysql examples | w3resource</title>
<meta name="description" content="example1-utc_time-function - php mysql examples | w3resource">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Current UTC time in numeric format:</h2>
<table class='table table-bordered'>
<tr>
<th>Current UTC time in numeric format</th>
</tr>
<?php
$hostname="your_hostname";
$username="your_username";
$password="your_password";
$db = "your_dbname";
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
foreach($dbh->query('SELECT UTC_TIME()+0') as $row) {
echo "<tr>";
echo "<td>" . $row['UTC_TIME()+0'] . "</td>";
echo "</tr>";
}
?>
</table>
</div>
</div>
</div>
</body>
</html>

Посмотреть пример в браузере

Все функции даты и времени:

Нажмите здесь, чтобы увидеть функции даты и времени MySQL.

Предыдущий: UTC_DATE ()
Далее: UTC_TIMESTAMP ()

Новый контент: Composer: менеджер зависимостей для PHP , R программирования


script1adsense4code
script1adsense5code
disqus2code
script1adsense6code
script1adsense7code
script1adsense8code
buysellads2code