Home Web Front-end JS Tutorial A small example of converting date to timestamp in javascript_javascript skills

A small example of converting date to timestamp in javascript_javascript skills

May 16, 2016 pm 05:39 PM
date Timestamp

Copy code The code is as follows:

/**
* Convert date to timestamp
* Date format 2011-02-02 21:12:13
* time_str: Date period 2011-02-02
* fix_time: Time period 21:12: 13
*/
function strtotime(time_str, fix_time) {
var time = (new Date()).getTime();

if(time_str) {//With date segment
var str = time_str.split('-');
if (3 === str.length) {
var year = parseInt( str[0]) - 0;
var month = parseInt(str[1]) - 0 - 1; //The month starts from 0
var day = parseInt(str[2]) - 0;

if(fix_time) {//There is a time period
var fix = fix_time.split(':');
if (3 === fix.length) {
var hour = parseInt( fix[0]) - 0;
var minute = parseInt(fix[1]) - 0;
var second = parseInt(fix[2]) - 0;
time = (new Date(year , month, day, hour, minute, second)).getTime();
}
} else {
time = (new Date(year, month, day)).getTime();
}
}
}
//The timestamp obtained by getTime() reaches the number of milliseconds
time = time / 1000;//Go to the number of seconds
return time;
}


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to search previous Weibo by date on Weibo_How to search previous Weibo by date on Weibo How to search previous Weibo by date on Weibo_How to search previous Weibo by date on Weibo Mar 30, 2024 pm 07:26 PM

1. First open the mobile web browser, search for the Weibo web version, and click the avatar button in the upper left corner after entering. 2. Then click Settings in the upper right corner. 3. Click the version switching option in settings. 4. Then select the color version option in the version switch. 5. Click Search to enter the search page. 6. After entering the keywords, click Find People. 7. When the search completion interface appears, click Filter. 8. Finally, enter the specific date in the release time column and click Filter.

How to remove the date that appears automatically when printing from PPT handouts How to remove the date that appears automatically when printing from PPT handouts Mar 26, 2024 pm 08:16 PM

1. Let me first talk about the method I used at the beginning, maybe everyone is using it too. First, open [View]——]Remarks Template[. 2. A place where you can actually see the date after opening it. 3. Select it first and delete it. 4. After deleting, click [Close Master View]. 5. Open the print preview again and find that the date is still there. 6. In fact, this date was not deleted here. It should be in the [Handout Master]. Look at the picture below. 7. Delete the date after you find it. 8. Now when you open the preview and take a look, the date is no longer there. Note: In fact, this method is also very easy to remember, because the printed handouts are handouts, so you should look for the [Handout Master].

Golang time processing: How to convert timestamp to string in Golang Golang time processing: How to convert timestamp to string in Golang Feb 24, 2024 pm 10:42 PM

Golang time conversion: How to convert timestamp to string In Golang, time operation is one of the very common operations. Sometimes we need to convert the timestamp into a string for easy display or storage. This article will introduce how to use Golang to convert timestamps to strings and provide specific code examples. 1. Conversion of timestamps and strings In Golang, timestamps are usually expressed in the form of integer numbers, which represent the number of seconds from January 1, 1970 to the current time. The string is

How to display date and seconds in the top bar of Ubuntu 17.10? How to display date and seconds in the top bar of Ubuntu 17.10? Jan 08, 2024 am 10:41 AM

By default, the top bar of Ubuntu 17.10 only has the current time and no date. What should I do if I want to display the date? Let’s take a look at the detailed tutorial below. 1. Open the terminal in the launcher, or press [Ctrl+Alt+T] 2. Enter in the terminal: sudoaptinstallgnome-tweak-tool 3. After the installation is completed, open the tweak tool 4. Click TopBar 5. Date is the date and seconds is the number of seconds 6. After setting it up, the date and seconds will be displayed on the time in the top bar.

How to use the time and date modules in Python How to use the time and date modules in Python Oct 16, 2023 am 08:11 AM

How to use the time and date modules in Python Introduction: In programming, dealing with time and dates are very common tasks. Python provides powerful time and date modules, making time and date operations easier and more convenient. This article will introduce the time and date modules in Python and provide specific code examples to help readers better understand and apply them. 1. Introducing the time and date module Python’s built-in time and date module is the datetime module. We need to introduce this module first.

How to change the date into a pound sign in Excel How to change the date into a pound sign in Excel Mar 20, 2024 am 11:46 AM

Excel software has very powerful data processing functions. We often use excel software to process various data. Sometimes when we enter a date in an excel cell, the date in excel changes to a pound sign. How can we display the data normally? Let’s take a look at the solution below. 1. First, we put the mouse on the column width line between columns AB, double-click and adjust the column width, as shown in the figure below. 2. After the column is widened, we find that numbers are displayed in the cells instead of dates. This is definitely incorrect. Then we should check the format of the cells, as shown in the figure below. 3. Click the "Number" option in the "Home" tab, and click "Other Number Format" in the drop-down menu, as shown in the figure below.

Best Practices for Timestamp Obtaining: A Powerful Tool in Golang Programming Best Practices for Timestamp Obtaining: A Powerful Tool in Golang Programming Dec 29, 2023 am 08:28 AM

Golang Programming Tool: Best Practices for Timestamp Obtaining Introduction: In software development, timestamp is a very common concept. It is a numeric value that identifies the occurrence of a specific event, usually representing the number of milliseconds or nanoseconds since some reference point in time. In Golang, processing timestamps is very simple and efficient. This article will introduce the best practices for obtaining timestamps in Golang and provide specific code examples. Text: Get the current timestamp In Golang, getting the current timestamp is very simple. we can

PHP data filtering: handling date and time input PHP data filtering: handling date and time input Jul 28, 2023 pm 07:41 PM

PHP Data Filtering: Processing Date and Time Input Overview: When developing web applications, it is often necessary to process date and time data entered by the user. Since user input may contain various formats and errors, effective data filtering and validation are necessary to ensure data accuracy and security. This article explains how to use PHP to handle date and time input, and provides corresponding code examples. Filtering and validation principles: Before processing date and time inputs, you first need to determine the corresponding filtering and validation principles. Here are some common ones

See all articles