php editor Xigua today will introduce to you how to use date and time and delete elapsed time to analyze stock quotes. In the stock market, obtaining and analyzing stock quotes in real time is a very important skill. By using the datetime function, we can get the current date and time and then calculate the update time of the stock quote by deleting the elapsed time. In this way, we can track changes in stock prices in real time and make appropriate decisions. Next, let’s learn about the specific steps!
Question content
I want to get the datetime from a string
(over the network) in ticker.C
format and parse it into Time
Object. ticker.C
looks like 2023-01-03 17:24:13.986722973 0100 CET m= 1.002332450
. It may have to remove the m= 1.002332450
elapsed time since I don't see a way to keep it in the Time
object.
Also, is there a way to get the format string from the Time object? Similar to mytime.GetFormat()
Workaround
The stringer format of time is documented here, https://pkg. go.dev/[email protected]#time.string:
String returns the time formatted using the format string
"2006-01-02 15:04:05.999999999 -0700 mst"
If the time has a monotonic clock reading, the returned string includes the last field "m=±
The returned string is used for debugging; for a stable serialized representation, use t.marshaltext, t.marshalbinary, or t.format with an explicit format string.
This indicates that you should not attempt to use the value, but instead rely on a properly marshalled (or formatted) string.
Not mentioned/suggested, time.marshaljson is an option:
marshaljson implements the json.marshaler interface. The time is a quoted string in rfc 3339 format, with subsecond precision added if present.
The sender and receiver don't need to do any special work to encode the time.time value to json and then decode it again:
type wiretick struct { tick time.time `json:"tick"` }
Here is a small example using this structure to encode and decode a stock symbol on a line, https://go.dev/play/p/fx73q8-kvfa, which produces the following output:
sent json-encoded tick on wire: {"tick":"2009-11-10t23:00:01z"} received tick from wire: {2009-11-10 23:00:01 +0000 utc} sent json-encoded tick on wire: {"tick":"2009-11-10t23:00:02z"} received tick from wire: {2009-11-10 23:00:02 +0000 utc} ...
Can you modify the value sent over the wire, or have someone else modify it to make it correct?
If not, This should be OK:
const stringerlayout = "2006-01-02 15:04:05.999999999 -0700 mst" timestr := "2009-11-10 23:00:10 +0000 utc m=+10.000000001" tickstr := timestr[:strings.index(timestr, "m=")-1] tick, _ := time.parse(stringerlayout, tickstr) fmt.printf("received from wire: \t %q\n", timestr) fmt.printf("chopped off monotonic: \t %q\n", tickstr) fmt.printf("tick is: \t\t %v\n", tick)
Received from wire: "2009-11-10 23:00:10 +0000 UTC m=+10.000000001" Chopped off monotonic: "2009-11-10 23:00:10 +0000 UTC" Tick is: 2009-11-10 23:00:10 +0000 UTC
The above is the detailed content of Parse stock quotes using datetime and delete elapsed time. For more information, please follow other related articles on the PHP Chinese website!

Mastering the strings package in Go language can improve text processing capabilities and development efficiency. 1) Use the Contains function to check substrings, 2) Use the Index function to find the substring position, 3) Join function efficiently splice string slices, 4) Replace function to replace substrings. Be careful to avoid common errors, such as not checking for empty strings and large string operation performance issues.

You should care about the strings package in Go because it simplifies string manipulation and makes the code clearer and more efficient. 1) Use strings.Join to efficiently splice strings; 2) Use strings.Fields to divide strings by blank characters; 3) Find substring positions through strings.Index and strings.LastIndex; 4) Use strings.ReplaceAll to replace strings; 5) Use strings.Builder to efficiently splice strings; 6) Always verify input to avoid unexpected results.

ThestringspackageinGoisessentialforefficientstringmanipulation.1)Itofferssimpleyetpowerfulfunctionsfortaskslikecheckingsubstringsandjoiningstrings.2)IthandlesUnicodewell,withfunctionslikestrings.Fieldsforwhitespace-separatedvalues.3)Forperformance,st

WhendecidingbetweenGo'sbytespackageandstringspackage,usebytes.Bufferforbinarydataandstrings.Builderforstringoperations.1)Usebytes.Bufferforworkingwithbyteslices,binarydata,appendingdifferentdatatypes,andwritingtoio.Writer.2)Usestrings.Builderforstrin

Go's strings package provides a variety of string manipulation functions. 1) Use strings.Contains to check substrings. 2) Use strings.Split to split the string into substring slices. 3) Merge strings through strings.Join. 4) Use strings.TrimSpace or strings.Trim to remove blanks or specified characters at the beginning and end of a string. 5) Replace all specified substrings with strings.ReplaceAll. 6) Use strings.HasPrefix or strings.HasSuffix to check the prefix or suffix of the string.

Using the Go language strings package can improve code quality. 1) Use strings.Join() to elegantly connect string arrays to avoid performance overhead. 2) Combine strings.Split() and strings.Contains() to process text and pay attention to case sensitivity issues. 3) Avoid abuse of strings.Replace() and consider using regular expressions for a large number of substitutions. 4) Use strings.Builder to improve the performance of frequently splicing strings.

Go's bytes package provides a variety of practical functions to handle byte slicing. 1.bytes.Contains is used to check whether the byte slice contains a specific sequence. 2.bytes.Split is used to split byte slices into smallerpieces. 3.bytes.Join is used to concatenate multiple byte slices into one. 4.bytes.TrimSpace is used to remove the front and back blanks of byte slices. 5.bytes.Equal is used to compare whether two byte slices are equal. 6.bytes.Index is used to find the starting index of sub-slices in largerslices.

Theencoding/binarypackageinGoisessentialbecauseitprovidesastandardizedwaytoreadandwritebinarydata,ensuringcross-platformcompatibilityandhandlingdifferentendianness.ItoffersfunctionslikeRead,Write,ReadUvarint,andWriteUvarintforprecisecontroloverbinary


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
